lightrail_client 2.0.0beta → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e30747a8e405655c72ec010cab80c24067b366ace6ed38796b29737b1edfe0e8
4
- data.tar.gz: 712921a9561b7abe9c262b87e4e25f5adf9a62c3606dd955d0a746eb6d513ef8
3
+ metadata.gz: 1fddd302fb68157084fe8f7562a55e8608f0fba7df36d9f680f36ee49a0a4d16
4
+ data.tar.gz: 5a78817518d33300f92af4fa25d071b293977f155c9c93c25fd22c2185bfa896
5
5
  SHA512:
6
- metadata.gz: da3a014cdc39b47aa21446c4f7f5c5bb2fb3f8a7b75c628918d1bd7d14e8d52272ca4a7b165a02077a5796615e7514fdd19499db005175613505d31113fe8082
7
- data.tar.gz: 7b9e7af56d31dcf249c9c4b35baa27fdc030d4293bdd76027e328cef7abcd19384586daf086dbb1bbf6534d2fc0e8af5bdb206bd8912ae5c0e51e290208dd3d6
6
+ metadata.gz: 6cfbd2c375746baff3bd6106f78b9a9409cd903f496ff7a09bf330ae41142eefbadfb52ac225e6f3d56939dd1abbcc3b188b2719773dd30ee680daccd037882e
7
+ data.tar.gz: ee3c53a25ebab1dc3a6572a299cc08158f773ba17edd3e28e094b3d7e0da1b1405da9cb79244f99ec12e8f736dd07e01907b1b78bd31ccdc9758164f3c57a8c2
data/.gitignore CHANGED
@@ -14,3 +14,6 @@
14
14
  # IntelliJ stuff
15
15
  *.iml
16
16
  .idea/
17
+
18
+ # Test secrets
19
+ .env
data/README.md CHANGED
@@ -1,300 +1,60 @@
1
1
  # Lightrail Client for Ruby
2
+ Lightrail is a modern platform for digital account credits, gift cards, promotions, and points (to learn more, visit [Lightrail](https://www.lightrail.com/)). This is a basic library for developers to easily connect with the Lightrail API using Ruby.
2
3
 
3
- Lightrail is a modern platform for digital account credits, gift cards, promotions, and points (to learn more, visit [Lightrail](https://www.lightrail.com/)). This is a basic library for developers to easily connect with the Lightrail API using Ruby. If you are looking for specific use cases or other languages, check out the complete list of all [Lightrail libraries](https://www.lightrail.com/docs/#client-libraries/client-libraries).
4
-
5
- ## Features
6
-
7
- The following features are supported in this version:
8
-
9
- - Account Credits: create, retrieve, charge, refund, balance-check, and fund.
10
- - Gift Cards: charge, refund, balance-check, and fund.
11
-
12
- Note that the Lightrail API supports many other features and we are working on covering them in this gem. For a complete list of Lightrail API features check out the [Lightrail API documentation](https://www.lightrail.com/docs/reference/).
13
-
14
- ## Related Projects
15
-
16
- Check out the full list of [Lightrail client libraries](https://www.lightrail.com/docs/#client-libraries/client-libraries).
17
-
18
- ## Usage
19
-
20
- Before using any parts of the library, you'll need to configure it to use your API key:
21
-
22
- ```ruby
23
- Lightrail.api_key = "<your lightrail API key>"
24
- ```
25
-
26
- *A note on sample code snippets: for reasons of legibility, the output for most calls has been simplified. Attributes of response objects that are not relevant here have been omitted.*
27
-
28
- ### Use Case: Account Credits Powered by Lightrail
29
-
30
- For a quick demonstration of implementing account credits using this library, see our [Accounts Quickstart](https://www.lightrail.com/docs/#accounts/accounts).
31
-
32
-
33
- ### Use Case: Gift Cards
34
-
35
- **Looking for Lightrail's Drop-In Gift Card Solution?**
36
-
37
- Check out our [Drop-in Gift Card documentation](https://www.lightrail.com/docs/#drop-in-gift-cards/drop-in-gift-cards) to get started.
38
-
39
- **Prefer to build it yourself?**
40
-
41
- The remainder of this document is a detailed overview of the methods this library offers for managing Gift Cards. It assumes familiarity with the concepts in our [Gift Card guide](https://github.com/Giftbit/Lightrail-API-Docs/blob/master/use-cases/gift-card.md).
42
-
43
- #### Balance Check
44
-
45
- There are several ways to check the balance of a gift card or code. Because you can attach conditional value to a card/code (for example, "get $5 off when you buy a red hat"), the available balance can vary depending on the transaction context.
46
-
47
- ##### Maximum Value
48
-
49
- To get the maximum value of a card/code, i.e. the sum of all active value stores, call either `Card.get_maximum_value(<CARD ID>)` or `Code.get_maximum_value(<CODE>)`. This method will return an integer which represents the sum of all active value stores in the smallest currency unit (e.g. cents):
50
-
51
- ```ruby
52
- maximum_gift_value = Lightrail::Card.get_maximum_value("<GIFT CARD ID>")
53
- # or use the code:
54
- # maximum_gift_value = Lightrail::Code.get_maximum_value("<GIFT CODE>")
55
-
56
- #=> 3500
57
- ```
58
-
59
- ##### Card/Code Details
60
-
61
- If you would like to see a breakdown of how the value is stored on a card or code you can use the `.get_details` method. This will return a breakdown of all attached value stores, along with other important information:
62
-
63
- ```
64
- gift_details = Lightrail::Card.get_details("<GIFT CARD ID>")
65
- # or use the code:
66
- # gift_details = Lightrail::Code.get_details("<GIFT CODE>")
67
-
68
- #=> {
69
- "valueStores": [
70
- {
71
- "valueStoreType": "PRINCIPAL",
72
- "value": 483,
73
- "state": "ACTIVE",
74
- "expires": null,
75
- "startDate": null,
76
- "programId": "program-123456",
77
- "valueStoreId": "value-11111111",
78
- "restrictions": []
79
- },
80
- {
81
- "valueStoreType": "ATTACHED",
82
- "value": 1234,
83
- "state": "ACTIVE",
84
- "expires": "2017-11-13T19:29:31.613Z",
85
- "startDate": null,
86
- "programId": "program-7890",
87
- "valueStoreId": "value-2222222",
88
- "restrictions": ["Valid for purchase of a red hat"]
89
- },
90
- {
91
- "valueStoreType": "ATTACHED",
92
- "value": 500,
93
- "state": "EXPIRED",
94
- "expires": "2017-09-13T19:29:37.464Z",
95
- "startDate": null,
96
- "programId": "program-24680",
97
- "valueStoreId": "value-3333333",
98
- "restrictions": ["Cart must have five or more items"]
99
- }
100
- ],
101
- "currency": "USD",
102
- "cardType": "GIFT_CARD",
103
- "asAtDate": "2017-11-06T19:29:41.533Z",
104
- "cardId": "card-12q4wresdgf6ey",
105
- "codeLastFour": "WXYZ"
106
- }
107
- }
108
- ```
109
-
110
- These details can be useful for showing a customer a summary of their gift balance, or for incentivizing further spending (e.g. "Add a red hat to your order to get $12.34 off").
111
-
112
- ##### Simulate Transaction
113
-
114
- If you would like to know how much is available for a specific transaction, use the `.simulate_charge` method. Simply pass in all the same parameters as you would to make a regular charge (see below) **including metadata** so that the Lightrail engine can assess whether necessary conditions are met for any attached value.
115
-
116
- The `value` of the response will indicate the maximum amount that can be charged given the context of the transaction, which can be useful when presenting your customer with a confirmation dialogue. The `value` is a drawdown amount and will therefore be negative:
117
-
118
- ```ruby
119
- simulated_charge = Lightrail::Card.simulate_charge({
120
- value: -1850,
121
- currency: 'USD',
122
- card_id: '<GIFT CARD ID>',
123
- metadata: {cart: {items_total: 5}},
124
- })
125
- #=> {
126
- "value"=>-1550,
127
- "userSuppliedId"=>"2bfb5ccb",
128
- "transactionType"=>"DRAWDOWN",
129
- "currency"=>"USD",
130
- "transactionBreakdown": [
131
- {
132
- "value": -1234,
133
- "valueAvailableAfterTransaction": 0,
134
- "valueStoreId": "value-4f9a362e7206445796d934727e0d2b27"
135
- },
136
- {
137
- "value": -616,
138
- "valueAvailableAfterTransaction": 0,
139
- "valueStoreId": "value-9850b36634b541f5bc6fd280b0198b3d",
140
- "restrictions": ["Cart must have five or more items"],
141
- }
142
- ],
143
- "transactionId": null,
144
- "dateCreated": null,
145
- #...
146
- }
147
- ```
148
-
149
- Note that because this is a simulated transaction and not a real transaction, the `transactionId` and `dateCreated` will both be `null`.
150
-
151
- #### Charging a Gift Card
152
-
153
- In order to make a charge, you can call `.charge` on either a `Code` or a `Card`. The minimum required parameters are the `fullCode` or `cardId`, the `currency`, and the `value` of the transaction (a negative integer in the smallest currency unit, e.g., 500 cents is 5 USD):
4
+ ## Installation
5
+ This gem is available on RubyGems.org. To use it in your project, add this line to your application's Gemfile:
154
6
 
155
7
  ```ruby
156
- gift_charge = Lightrail::Code.charge({
157
- value: -2500,
158
- currency: 'USD',
159
- code: '<GIFT CODE>'
160
- })
161
- #=> {
162
- "value"=>-1850,
163
- "userSuppliedId"=>"2bfb5ccb",
164
- "transactionType"=>"DRAWDOWN",
165
- "currency"=>"USD",
166
- #...
167
- }
8
+ gem 'lightrail_client'
168
9
  ```
169
10
 
170
- **A note on idempotency:** All calls to create or act on transactions (refund, void, capture) can optionally take a `userSuppliedId` parameter. The `userSuppliedId` is a client-side identifier (unique string) which is used to ensure idempotency (for more details, see the [API documentation](https://www.lightrail.com/docs/reference/)). If you do not provide a `userSuppliedId`, the gem will create one for you for any calls that require one.
11
+ And then execute:
171
12
 
172
- ```ruby
173
- gift_charge = Lightrail::Code.charge({
174
- value: -1850,
175
- currency: 'USD',
176
- code: '<GIFT CODE>',
177
- userSuppliedId: 'order-13jg9s0era9023-u9a-0ea'
178
- })
179
13
  ```
180
-
181
- Note that Lightrail does not support currency exchange and the currency provided to these methods must match the currency of the gift card.
182
-
183
- For more details on the parameters that you can pass in for a charge request and the response that you will get back, see the [API documentation](https://www.lightrail.com/docs/reference/).
184
-
185
- #### Authorize-Capture Flow
186
-
187
- By adding ` pending: true` to your charge param hash when calling either `Card.charge` or `Code.charge`, you can create a pre-authorized pending transaction. When you are ready to capture or void it, you will call `Transaction.capture` or `Transaction.void` and pass in the response you get back from the call to create the pending charge:
188
-
189
- ```ruby
190
- gift_charge = Lightrail::Code.charge({
191
- value: -1850,
192
- currency: 'USD',
193
- code: '<GIFT CODE>',
194
- pending: true,
195
- })
196
- # later on
197
- Lightrail::Transaction.capture(gift_charge)
198
- #=> {
199
- "value"=>-1850,
200
- "userSuppliedId"=>"12c2d18f",
201
- "dateCreated"=>"2017-05-29T13:37:02.756Z",
202
- "transactionType"=>"DRAWDOWN",
203
- "transactionAccessMethod"=>"RAWCODE",
204
- "cardId"=>"<GIFT CARD ID>",
205
- "currency"=>"USD",
206
- "transactionId"=>"transaction-8483d9",
207
- "parentTransactionId"=>"transaction-cf353236"
208
- }
209
-
210
- # or
211
- Lightrail::Transaction.void(gift_charge)
212
- #=> {
213
- "value"=>-1850,
214
- "userSuppliedId"=>"12c2d18f",
215
- "dateCreated"=>"2017-05-29T13:37:02.756Z",
216
- "transactionType"=>"PENDING_VOID",
217
- "transactionAccessMethod"=>"RAWCODE",
218
- "cardId"=>"<GIFT CARD ID>",
219
- "currency"=>"USD",
220
- "transactionId"=>"transaction-d10e76",
221
- "parentTransactionId"=>"transaction-cf353236"
222
- }
14
+ $ bundle
223
15
  ```
224
16
 
225
- Note that `Transaction.void` and `Transaction.capture` will each return a **new transaction** and will not modify the original pending transaction they are called on. These new transactions will have their own `transactionId`. If you need to record the transaction ID of the captured or canceled charge, you can get it from the hash returned by these methods.
226
-
227
- #### Refunding a Charge
228
-
229
- You can undo a charge by calling `Transaction.refund` and passing in the details of the transaction you wish to refund. This will create a new `refund` transaction which will return the charged amount back to the card. If you need the transaction ID of the refund transaction, you can find it in the response from the API.
17
+ ## Usage
18
+ Before using any parts of the library, you'll need to configure it to use your API key:
230
19
 
231
20
  ```ruby
232
- gift_charge = Lightrail::Code.charge(<CHARGE PARAMS>)
233
-
234
- # later on
235
- Lightrail::Transaction.refund(gift_charge)
236
- #=> {
237
- "value"=>1850,
238
- "userSuppliedId"=>"873b08ab",
239
- "dateCreated"=>"2017-05-29T13:37:02.756Z",
240
- "transactionType"=>"DRAWDOWN_REFUND",
241
- "transactionAccessMethod"=>"CARDID",
242
- "cardId"=>"<GIFT CARD ID>",
243
- "currency"=>"USD",
244
- "transactionId"=>"transaction-0f2a67",
245
- "parentTransactionId"=>"transaction-2271e3"
246
- }
21
+ Lightrail.api_key = "<your lightrail API key>"
247
22
  ```
248
23
 
249
- Note that this does not necessarily mean that the refunded amount is available for a re-charge. In the edge case where the funds for the original charge came from a promotion which has now expired, refunding will return those funds back to the now-expired value store and therefore the value will not be available for re-charge. To learn more about using value stores for temporary promotions, see the [Promotions Quickstart](https://www.lightrail.com/docs/#promotions/promotions).
250
-
251
- #### Funding a Gift Card
252
-
253
- To fund a gift card, you can call `Card.fund`. Note that the Lightrail API does not permit funding a gift card by its `code` and the only way to fund a card is by providing its `cardId`:
24
+ If generating shopper tokens, you'll also need to set the shared secret.
254
25
 
255
26
  ```ruby
256
- gift_fund = Lightrail::Card.fund({
257
- value: 500,
258
- currency: 'USD',
259
- card_id: '<GIFT CARD ID>',
260
- })
261
- #=> {
262
- "value"=>500,
263
- "userSuppliedId"=>"7676c986",
264
- "dateCreated"=>"2017-05-29T13:37:02.756Z",
265
- "transactionType"=>"FUND",
266
- "transactionAccessMethod"=>"CARDID",
267
- "cardId"=>"<GIFT CARD ID>",
268
- "currency"=>"USD",
269
- "transactionId"=>"transaction-dee3ee7"
270
- }
27
+ Lightrail.shared_secret = "<your Lightrail shared secret>"
271
28
  ```
272
29
 
273
-
274
- ## Installation
275
-
276
- This gem is available on RubyGems.org. To use it in your project, add this line to your application's Gemfile:
277
-
30
+ ### Example Usage
31
+ A quick example of creating a Value.
278
32
  ```ruby
279
- gem 'lightrail_client'
33
+ Lightrail::Values.create(
34
+ {
35
+ id: "unique-id-123",
36
+ currency: "USD",
37
+ balance: 10
38
+ })
280
39
  ```
281
40
 
282
- And then execute:
41
+ Full argument parameters can be found in the [Lightrail API Docs](https://lightrailapi.docs.apiary.io/#introduction). Arguments should be passed in `camelCased` exactly as they appear in the API Docs.
283
42
 
284
- ```
285
- $ bundle
286
- ```
43
+ If you'd like to see more examples of using the gem, our full Ruby tests can be viewed [here](https://github.com/Giftbit/lightrail-client-ruby/tree/master/spec/resources).
287
44
 
288
45
  ## Contributing
289
-
290
46
  Bug reports and pull requests are welcome on GitHub at https://github.com/Giftbit/lightrail-client-ruby.
291
47
 
292
48
  ## Development
293
-
294
49
  After checking out the repo, run `bin/setup` to install dependencies, then run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
295
50
 
296
51
  To install this gem onto your local machine, run `bundle exec rake install`.
297
52
 
53
+ You'll also need to add a .env file.
54
+ ```
55
+ LIGHTRAIL_TEST_API_KEY=
56
+ ```
57
+
298
58
  ### Publishing
299
59
 
300
60
  Make sure to bump the version number before publishing changes.
@@ -0,0 +1,79 @@
1
+ module Lightrail
2
+ class Connection
3
+ def self.connection
4
+ conn = Faraday.new Lightrail.api_base, ssl: {version: :TLSv1_2}
5
+ conn.headers['Content-Type'] = 'application/json; charset=utf-8'
6
+ conn.headers['Authorization'] = "Bearer #{Lightrail.api_key}"
7
+ conn.headers['User-Agent'] = "Lightrail-Ruby/#{Gem.loaded_specs['lightrail_client'].version.version}"
8
+ conn
9
+ end
10
+
11
+ def self.post (url, body)
12
+ resp = Lightrail::Connection.connection.post do |req|
13
+ req.url url
14
+ req.body = JSON.generate(body)
15
+ end
16
+ self.handle_response(resp)
17
+ end
18
+
19
+ def self.patch (url, body)
20
+ resp = Lightrail::Connection.connection.patch do |req|
21
+ req.url url
22
+ req.body = JSON.generate(body)
23
+ end
24
+ self.handle_response(resp)
25
+ end
26
+
27
+ def self.delete (url)
28
+ resp = Lightrail::Connection.connection.delete do |req|
29
+ req.url url
30
+ end
31
+ self.handle_response(resp)
32
+ end
33
+
34
+ def self.get(url, query_params = {})
35
+ resp = Lightrail::Connection.connection.get {|req| req.url url, query_params}
36
+ self.handle_response(resp, false)
37
+ end
38
+
39
+ def self.handle_response(response, error_on_404 = true)
40
+ case response.status
41
+ when 200...300
42
+ return format_response(response)
43
+ else
44
+ if response.status == 404 && !error_on_404
45
+ return format_response(response)
46
+ end
47
+ body = JSON.parse(response.body) || {}
48
+ raise LightrailError.new("Server responded with: (#{response.status}) #{body['message'] || ''}", response.status, response)
49
+ end
50
+ end
51
+
52
+ def self.format_response(response)
53
+ body = JSON.parse(response.body) || {}
54
+ text = response.body
55
+ links, limit, max_limit = nil
56
+ if response.headers["link"]
57
+ links = self.parse_link_headers(response.headers["link"])
58
+ limit = response.headers["limit"].to_i
59
+ max_limit = response.headers["max-limit"].to_i
60
+ end
61
+ return LightrailResponse.new(body, text, response.status, links, limit, max_limit)
62
+ end
63
+
64
+ def self.parse_link_headers(link_headers)
65
+ links = []
66
+ link_headers.split(",").each do |link_header|
67
+ link = {
68
+ url: link_header[/(?<=\<)(.*?)(?=\>)/, 1],
69
+ rel: link_header[/(?<=\")(.*?)(?=\")/, 1]
70
+ }
71
+ CGI::parse(URI::parse(link[:url]).query).each do |key, values|
72
+ link[key.to_sym] = values[0] # CGI parse returns hash of key => [values]. [values] will always be of length 1 so this removes the array.
73
+ end
74
+ links.push(link)
75
+ end
76
+ return links
77
+ end
78
+ end
79
+ end
@@ -1,11 +1,11 @@
1
1
  module Lightrail
2
2
  class LightrailError < StandardError
3
- attr_reader :message
4
- attr_accessor :response
3
+ attr_reader :message, :status, :response
5
4
 
6
- def initialize (message='', response)
5
+ def initialize (message = '', status = nil, response = nil)
7
6
  @message = message
8
7
  @response = response
8
+ @status = status
9
9
  end
10
10
  end
11
11
 
@@ -0,0 +1,14 @@
1
+ module Lightrail
2
+ class LightrailResponse
3
+ attr_reader :body, :text, :status, :links, :max_limit, :limit
4
+
5
+ def initialize (body, text, status, links = nil, limit = nil, max_limit = nil)
6
+ @body = body
7
+ @text = text
8
+ @links = links
9
+ @status = status
10
+ @max_limit = max_limit
11
+ @limit = limit
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module Lightrail
2
+ class Contacts
3
+ def self.create(params)
4
+ Lightrail::Connection.post("#{Lightrail.api_base}/contacts", params)
5
+ end
6
+
7
+ def self.get(id)
8
+ Lightrail::Validators.validate_id(id)
9
+ Lightrail::Connection.get("#{Lightrail.api_base}/contacts/#{CGI::escape(id)}")
10
+ end
11
+
12
+ def self.list(query_params = {})
13
+ Lightrail::Connection.get("#{Lightrail.api_base}/contacts", query_params)
14
+ end
15
+
16
+ def self.update(id, params)
17
+ Lightrail::Validators.validate_id(id)
18
+ Lightrail::Connection.patch("#{Lightrail.api_base}/contacts/#{CGI::escape(id)}", params)
19
+ end
20
+
21
+ def self.attach_value_to_contact(id, params)
22
+ Lightrail::Validators.validate_id(id, "contact_id")
23
+ Lightrail::Connection.post("#{Lightrail.api_base}/contacts/#{CGI::escape(id)}/values/attach", params)
24
+ end
25
+
26
+ def self.list_contact_values(id, query_params = {})
27
+ Lightrail::Connection.get("#{Lightrail.api_base}/contacts/#{CGI::escape(id)}/values", query_params)
28
+ end
29
+
30
+ def self.delete(id)
31
+ Lightrail::Validators.validate_id(id)
32
+ Lightrail::Connection.delete("#{Lightrail.api_base}/contacts/#{CGI::escape(id)}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module Lightrail
2
+ class Currencies
3
+ def self.create(params)
4
+ Lightrail::Connection.post("#{Lightrail.api_base}/currencies", params)
5
+ end
6
+
7
+ def self.get(code)
8
+ Lightrail::Validators.validate_id(code)
9
+ Lightrail::Connection.get("#{Lightrail.api_base}/currencies/#{CGI::escape(code)}")
10
+ end
11
+
12
+ def self.list(query_params = {})
13
+ Lightrail::Connection.get("#{Lightrail.api_base}/currencies", query_params)
14
+ end
15
+
16
+ def self.update(code, params)
17
+ Lightrail::Validators.validate_id(code)
18
+ Lightrail::Connection.patch("#{Lightrail.api_base}/currencies/#{CGI::escape(code)}", params)
19
+ end
20
+
21
+ def self.delete(code)
22
+ Lightrail::Validators.validate_id(code)
23
+ Lightrail::Connection.delete("#{Lightrail.api_base}/currencies/#{CGI::escape(code)}")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ module Lightrail
2
+ class Programs
3
+ def self.create(params)
4
+ Lightrail::Connection.post("#{Lightrail.api_base}/programs", params)
5
+ end
6
+
7
+ def self.get(id)
8
+ Lightrail::Validators.validate_id(id)
9
+ Lightrail::Connection.get("#{Lightrail.api_base}/programs/#{CGI::escape(id)}")
10
+ end
11
+
12
+ def self.list(query_params = {})
13
+ Lightrail::Connection.get("#{Lightrail.api_base}/programs", query_params)
14
+ end
15
+
16
+ def self.update(id, params)
17
+ Lightrail::Validators.validate_id(id)
18
+ Lightrail::Connection.patch("#{Lightrail.api_base}/programs/#{CGI::escape(id)}", params)
19
+ end
20
+
21
+ def self.create_issuance(program_id, params)
22
+ Lightrail::Validators.validate_id(program_id, "program_id")
23
+ Lightrail::Connection.post("#{Lightrail.api_base}/programs/#{CGI::escape(program_id)}/issuances", params)
24
+ end
25
+
26
+ def self.list_issuances(program_id, query_params = {})
27
+ Lightrail::Validators.validate_id(program_id, "program_id")
28
+ Lightrail::Connection.get("#{Lightrail.api_base}/programs/#{CGI::escape(program_id)}/issuances", query_params)
29
+ end
30
+
31
+ def self.get_issuance(program_id, issuance_id)
32
+ Lightrail::Validators.validate_id(program_id, "program_id")
33
+ Lightrail::Validators.validate_id(issuance_id, "issuance_id")
34
+ Lightrail::Connection.get("#{Lightrail.api_base}/programs/#{CGI::escape(program_id)}/issuances/#{CGI::escape(issuance_id)}")
35
+ end
36
+
37
+ def self.delete(id)
38
+ Lightrail::Validators.validate_id(id)
39
+ Lightrail::Connection.delete("#{Lightrail.api_base}/programs/#{CGI::escape(id)}")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,47 @@
1
+ module Lightrail
2
+ class Transactions
3
+ def self.checkout(params)
4
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/checkout", params)
5
+ end
6
+
7
+ def self.debit(params)
8
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/debit", params)
9
+ end
10
+
11
+ def self.credit(params)
12
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/credit", params)
13
+ end
14
+
15
+ def self.transfer(params)
16
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/transfer", params)
17
+ end
18
+
19
+ def self.reverse(id, params)
20
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/#{CGI::escape(id)}/reverse", params)
21
+ end
22
+
23
+ def self.capture_pending(id, params)
24
+ Lightrail::Validators.validate_id(id, "transaction_id")
25
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/#{CGI::escape(id)}/capture", params)
26
+ end
27
+
28
+ def self.void_pending(id, params)
29
+ Lightrail::Validators.validate_id(id, "pending_id")
30
+ Lightrail::Connection.post("#{Lightrail.api_base}/transactions/#{CGI::escape(id)}/void", params)
31
+ end
32
+
33
+ def self.get(id)
34
+ Lightrail::Validators.validate_id(id)
35
+ Lightrail::Connection.get("#{Lightrail.api_base}/transactions/#{CGI::escape(id)}")
36
+ end
37
+
38
+ def self.list(query_params)
39
+ Lightrail::Connection.get("#{Lightrail.api_base}/transactions", query_params)
40
+ end
41
+
42
+ def self.get_transaction_chain(id)
43
+ Lightrail::Validators.validate_id(id)
44
+ Lightrail::Connection.get("#{Lightrail.api_base}/transactions/#{CGI::escape(id)}/chain")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ module Lightrail
2
+ class Values
3
+ def self.create(params)
4
+ Lightrail::Connection.post("#{Lightrail.api_base}/values", params)
5
+ end
6
+
7
+ def self.get(id, query_params = {})
8
+ Lightrail::Validators.validate_id(id)
9
+ Lightrail::Connection.get("#{Lightrail.api_base}/values/#{CGI::escape(id)}", query_params)
10
+ end
11
+
12
+ def self.list(query_params = {})
13
+ Lightrail::Connection.get("#{Lightrail.api_base}/values", query_params)
14
+ end
15
+
16
+ def self.update(id, params)
17
+ Lightrail::Validators.validate_id(id)
18
+ Lightrail::Connection.patch("#{Lightrail.api_base}/values/#{CGI::escape(id)}", params)
19
+ end
20
+
21
+ def self.change_code(id, params)
22
+ Lightrail::Validators.validate_id(id)
23
+ Lightrail::Connection.post("#{Lightrail.api_base}/values/#{CGI::escape(id)}/changeCode", params)
24
+ end
25
+
26
+ def self.delete(id)
27
+ Lightrail::Validators.validate_id(id)
28
+ Lightrail::Connection.delete("#{Lightrail.api_base}/values/#{CGI::escape(id)}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Lightrail
2
+ class Validators
3
+ def self.validate_id(id, key = "id")
4
+ raise Lightrail::BadParameterError.new("Argument #{key} must be set.") unless ((id.is_a? String) || (id.is_a? Integer))
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Lightrail
2
- VERSION = "2.0.0beta"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -8,7 +8,16 @@ require "base64"
8
8
  require "lightrail_client/version"
9
9
 
10
10
  require "lightrail_client/errors"
11
+ require "lightrail_client/lightrail_response_objects"
11
12
  require "lightrail_client/shopper_token_factory"
13
+ require "lightrail_client/connection"
14
+ require "lightrail_client/validators"
15
+
16
+ require "lightrail_client/resources/contacts"
17
+ require "lightrail_client/resources/currencies"
18
+ require "lightrail_client/resources/programs"
19
+ require "lightrail_client/resources/transactions"
20
+ require "lightrail_client/resources/values"
12
21
 
13
22
  module Lightrail
14
23
  class << self
@@ -30,13 +30,14 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.15"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
36
- spec.add_development_dependency "pry-byebug", "~>3.4"
33
+ spec.add_development_dependency "bundler", "~> 1.17"
34
+ spec.add_development_dependency "rake", "~> 10.5"
35
+ spec.add_development_dependency "rspec", "~> 3.8"
36
+ spec.add_development_dependency "pry-byebug", "~>3.6"
37
+ spec.add_development_dependency "dotenv", "~> 2.5"
37
38
 
38
- spec.add_runtime_dependency "faraday", "~>0.12"
39
- spec.add_runtime_dependency "json", "~>1.7"
40
- spec.add_runtime_dependency "openssl", "~>2.0"
39
+ spec.add_runtime_dependency "faraday", "~>0.15"
40
+ spec.add_runtime_dependency "json", "~>1.8"
41
+ spec.add_runtime_dependency "openssl", "~>2.1"
41
42
  spec.add_runtime_dependency "jwt", "~>2.1"
42
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightrail_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0beta
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lightrail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-08 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,98 +16,112 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '1.17'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.8'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.4'
61
+ version: '3.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.4'
68
+ version: '3.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: faraday
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.12'
89
+ version: '0.15'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.12'
96
+ version: '0.15'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: json
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '1.7'
103
+ version: '1.8'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '1.7'
110
+ version: '1.8'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: openssl
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '2.0'
117
+ version: '2.1'
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '2.0'
124
+ version: '2.1'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: jwt
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,8 +154,16 @@ files:
140
154
  - bin/console
141
155
  - bin/setup
142
156
  - lib/lightrail_client.rb
157
+ - lib/lightrail_client/connection.rb
143
158
  - lib/lightrail_client/errors.rb
159
+ - lib/lightrail_client/lightrail_response_objects.rb
160
+ - lib/lightrail_client/resources/contacts.rb
161
+ - lib/lightrail_client/resources/currencies.rb
162
+ - lib/lightrail_client/resources/programs.rb
163
+ - lib/lightrail_client/resources/transactions.rb
164
+ - lib/lightrail_client/resources/values.rb
144
165
  - lib/lightrail_client/shopper_token_factory.rb
166
+ - lib/lightrail_client/validators.rb
145
167
  - lib/lightrail_client/version.rb
146
168
  - lightrail_client.gemspec
147
169
  homepage: https://www.lightrail.com/
@@ -160,12 +182,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
182
  version: '0'
161
183
  required_rubygems_version: !ruby/object:Gem::Requirement
162
184
  requirements:
163
- - - ">"
185
+ - - ">="
164
186
  - !ruby/object:Gem::Version
165
- version: 1.3.1
187
+ version: '0'
166
188
  requirements: []
167
189
  rubyforge_project:
168
- rubygems_version: 2.7.8
190
+ rubygems_version: 2.7.7
169
191
  signing_key:
170
192
  specification_version: 4
171
193
  summary: A client library for the Lightrail API