Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Current Version
-

2.4.0 December 6, 2017
- Add `Links` resource

2.3.0 June 22, 2017
- Add api_version to Client config

Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ We currently expose the following resources to manage:
* [`Customers`](#customers)
* [`Merchants`](#merchants)
* [`Orders`](#orders)
* [`Links`](#links)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetical order


### Accounts

Expand Down Expand Up @@ -244,6 +245,42 @@ puts response
# => Button::Response()
```

### Links

##### Create

```ruby
require 'button'

client = Button::Client.new('sk-XXX')

response = client.links.create({
url: "https://www.jet.com",
experience: {
btn_pub_ref: "my-pub-ref",
btn_pub_user: "user-id"
}
})

puts response
# => Button::Response()
```

##### Get Info

```ruby
require 'button'

client = Button::Client.new('sk-XXX')

response = client.links.get_info({
url: "https://www.jet.com"
})

puts response
# => Button::Response()
```

## Response

An instance of the `Button::Response` class will be returned by all API methods. It is used to read the response data as well as collect any meta data about the response, like potential next and previous cursors to more data in a paged endpoint.
Expand Down
4 changes: 3 additions & 1 deletion lib/button/client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'button/resources/accounts'
require 'button/resources/customers'
require 'button/resources/links'
require 'button/resources/merchants'
require 'button/resources/orders'
require 'button/errors'
Expand Down Expand Up @@ -28,6 +29,7 @@ def initialize(api_key, config = {})

@accounts = Accounts.new(api_key, config_with_defaults)
@customers = Customers.new(api_key, config_with_defaults)
@links = Links.new(api_key, config_with_defaults)
@merchants = Merchants.new(api_key, config_with_defaults)
@orders = Orders.new(api_key, config_with_defaults)
end
Expand All @@ -44,7 +46,7 @@ def merge_defaults(config)
}
end

attr_reader :accounts, :customers, :merchants, :orders
attr_reader :accounts, :customers, :merchants, :orders, :links
private :merge_defaults
end
end
29 changes: 29 additions & 0 deletions lib/button/resources/links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'button/resources/resource'

module Button
# https://www.usebutton.com/developers/api-reference/
#
class Links < Resource
def path
'/v1/links'
end

# Create a Link
#
# @param [Hash] link the link to create
# @return [Button::Response] the API response
#
def create(link)
api_post(path, link)
end

# Get information for Link
#
# @param [Hash] link the link to get information on
# @return [Button::Response] the API response
#
def get_info(link)
api_post(path + '/info', link)
end
end
end
2 changes: 1 addition & 1 deletion lib/button/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Button
VERSION = '2.3.0'.freeze
VERSION = '2.4.0'.freeze
end
40 changes: 40 additions & 0 deletions test/button/resources/links_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require File.expand_path('../../../test_helper', __FILE__)

class LinksTest < Test::Unit::TestCase
def setup
@links = Button::Links.new(
'sk-XXX',
secure: true,
timeout: nil,
hostname: 'api.usebutton.com',
port: 443
)

@headers = {
'Authorization' => 'Basic c2stWFhYOg==',
'User-Agent' => Button::Resource::USER_AGENT
}
end

def teardown
WebMock.reset!
end

def test_create
stub_request(:post, 'https://api.usebutton.com/v1/links')
.with(body: '{"a":1}', headers: @headers)
.to_return(status: 200, body: '{ "meta": { "status": "ok" }, "object": { "a": 1 } }')

response = @links.create(a: 1)
assert_equal(response.data[:a], 1)
end

def test_get_info
stub_request(:post, 'https://api.usebutton.com/v1/links/info')
.with(body: '{"a":1}', headers: @headers)
.to_return(status: 200, body: '{ "meta": { "status": "ok" }, "object": { "a": 1 } }')

response = @links.get_info(a: 1)
assert_equal(response.data[:a], 1)
end
end