button 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4e8a1c32105113a4aef997c0174e04b9837bcd21
4
- data.tar.gz: c2b15b144b667bc8a20ae4be470a37b899251acc
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTRlYTE4OWNjZGQyY2I0MzE1ZTU5NTg2OTA2YTFiMTA5MTU1ZDQ4Yw==
5
+ data.tar.gz: !binary |-
6
+ NzJjMWY5NDcyZDE3OWExNjkwYWQwYTc4YjY5YjdiMmJlN2UzYWUzMg==
5
7
  SHA512:
6
- metadata.gz: 2257e0e49af63ae6f832dc56f5b6da8009b68bd449e2505dfce55d00554a8ea56c31031513fb3aefc3a80dc8cc8b818b2206f5a952740cf0c50bf1ca00ca21f9
7
- data.tar.gz: a49d781607063a3e2635eeb957624bc7c5723d552a1839445f6b8e3410ff9e7fc8020c4468dbe04319027ce0c03cc8cc211891dbfc5dd65eac2be987fe53db96
8
+ metadata.gz: !binary |-
9
+ MDVkZjFjMjI5ZWU1YjE3NGUxODgzMWM2YTJjY2I2NmZiZjQ4YmQ0ZTFhNWE4
10
+ ZTBkZDMzNzgyZGVlYjIwZjY3MTQxNzIwZDY2Y2U1NTBhYjFkMDNlMzhjM2Ew
11
+ ZjZiMjg0YjMzZDEzMzgxZDk3YzYyZTAxMDE5NGJkNDk0NjE5OGM=
12
+ data.tar.gz: !binary |-
13
+ ODNmYzAzZWRiOWIwYWVlZTYyZTBiOWQ1YjgxMjk3OWY1MDlkOTIzYmNhOTQ4
14
+ YjVkMWViYjM1YjFiNmEwZTI5ZTQ3NzE2YjA4MjUwZDRiZDMyNDM5ODJlYTUz
15
+ Zjc0ZDZjMjYyZjVmZjNiODU1NTc3N2Q5MTk4ZWY2Y2ViMzEyMmQ=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # button-client-ruby [![Build Status](https://travis-ci.com/button/button-client-ruby.svg?token=HswVzGqEpwteP838Y3ss&branch=master)](https://travis-ci.com/button/button-client-ruby)
1
+ # button-client-ruby [![Build Status](https://travis-ci.org/button/button-client-ruby.svg?branch=master)](https://travis-ci.org/button/button-client-ruby)
2
2
 
3
3
  This module is a thin client for interacting with Button's API.
4
4
 
@@ -53,6 +53,28 @@ puts response.to_hash()
53
53
 
54
54
  n.b. the keys of the response hash will always be symbols.
55
55
 
56
+ ## Configuration
57
+
58
+ You may optionally supply a config argument with your API key:
59
+
60
+ ```ruby
61
+ require 'button'
62
+
63
+ client = Button::Client.new('sk-XXX', {
64
+ hostname: 'api.testsite.com',
65
+ port: 3000,
66
+ secure: false,
67
+ timeout: 5 # seconds
68
+ })
69
+ ```
70
+
71
+ The supported options are as follows:
72
+
73
+ * `hostname`: Defaults to `api.usebutton.com`.
74
+ * `port`: Defaults to `443` if `config.secure`, else defaults to `80`.
75
+ * `secure`: Whether or not to use HTTPS. Defaults to True. **N.B: Button's API is only exposed through HTTPS. This option is provided purely as a convenience for testing and development.**
76
+ * `timeout`: The time in seconds that may elapse before network requests abort. Defaults to `nil`.
77
+
56
78
  ## Resources
57
79
 
58
80
  We currently expose only one resource to manage, `Orders`.
@@ -72,7 +94,8 @@ response = client.orders.create({
72
94
  total: 50,
73
95
  currency: 'USD',
74
96
  order_id: '1994',
75
- finalization_date: '2017-08-02T19:26:08Z'
97
+ finalization_date: '2017-08-02T19:26:08Z',
98
+ btn_ref: 'srctok-XXX'
76
99
  })
77
100
 
78
101
  puts response
data/lib/button/client.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'button/resources/orders'
2
2
  require 'button/errors'
3
3
 
4
+ NO_API_KEY_MESSAGE = 'Must provide a Button API key. Find yours at '\
5
+ 'https://app.usebutton.com/settings/organization'
6
+
4
7
  module Button
5
8
  # Client is the top-level interface for the Button API. It exposes one
6
9
  # resource currently: `.orders`. It requires a valid API key to make
@@ -13,14 +16,28 @@ module Button
13
16
  # puts client.orders.get("btnorder-XXX")
14
17
  #
15
18
  class Client
16
- def initialize(api_key)
19
+ def initialize(api_key, config = {})
17
20
  if api_key.nil? || api_key.empty?
18
- raise ButtonClientError, 'Must provide a Button API key. Find yours at https://app.usebutton.com/settings/organization'
21
+ raise ButtonClientError, NO_API_KEY_MESSAGE
19
22
  end
20
23
 
21
- @orders = Orders.new(api_key)
24
+ config_with_defaults = merge_defaults(config)
25
+
26
+ @orders = Orders.new(api_key, config_with_defaults)
27
+ end
28
+
29
+ def merge_defaults(config)
30
+ secure = config.fetch(:secure, true)
31
+
32
+ return {
33
+ secure: secure,
34
+ timeout: config.fetch(:timeout, nil),
35
+ hostname: config.fetch(:hostname, 'api.usebutton.com'),
36
+ port: config.fetch(:port, secure ? 443 : 80)
37
+ }
22
38
  end
23
39
 
24
40
  attr_reader :orders
41
+ private :merge_defaults
25
42
  end
26
43
  end
@@ -24,14 +24,21 @@ module Button
24
24
  # end
25
25
  #
26
26
  class Resource
27
- HOST = 'api.usebutton.com'.freeze
28
- PORT = 443
29
27
  USER_AGENT = "Button/#{Button::VERSION} ruby/#{RUBY_VERSION}".freeze
30
28
 
31
- def initialize(api_key)
29
+ def initialize(api_key, config)
32
30
  @api_key = api_key
33
- @http = Net::HTTP.new(HOST, PORT)
34
- @http.use_ssl = true
31
+ @config = config
32
+ @http = Net::HTTP.new(config[:hostname], config[:port])
33
+ @http.use_ssl = config[:secure]
34
+
35
+ if not config[:timeout].nil?
36
+ @http.read_timeout = config[:timeout]
37
+ end
38
+ end
39
+
40
+ def timeout
41
+ @http.read_timeout
35
42
  end
36
43
 
37
44
  # Performs an HTTP GET at the provided path.
@@ -96,6 +103,7 @@ module Button
96
103
  raise ButtonClientError, "Invalid response: #{parsed}"
97
104
  end
98
105
 
106
+ attr_accessor :config
99
107
  private :api_request, :process_response
100
108
  end
101
109
  end
@@ -1,3 +1,3 @@
1
1
  module Button
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: button
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Button
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Button is a contextual acquisition channel and closed-loop attribution
14
14
  and affiliation system for mobile commerce.
@@ -38,17 +38,17 @@ require_paths:
38
38
  - lib
39
39
  required_ruby_version: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ">="
41
+ - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.9.3
44
44
  required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
50
  rubyforge_project:
51
- rubygems_version: 2.5.1
51
+ rubygems_version: 2.4.8
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: ruby client for the Button Order API