gyft 0.0.3 → 0.0.4

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,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 430c2c8154291101cc09ba954792337d3d81ec03
4
- data.tar.gz: 2cc655c695a6b1808c3ae2bab91b1500dc933098
3
+ metadata.gz: 8e6eeace4f248958e53b36ea5adcff736fbdedc8
4
+ data.tar.gz: dc6b3b16b6c9b3cc78c6c9c6958ead8a44178aa7
5
5
  SHA512:
6
- metadata.gz: 82f72fb65b37d149546bea4bc5df1ebc2101579473472f2a541583f7c3149f32f9058a3b46a2998b7ba500e1f630541cc8585535cf9c59b91c3f61ba46813394
7
- data.tar.gz: 6903ddb6c74b2bdaa0d3e1bd3923ce366377c3a75ca23ebc96bfadbe714319e40c953615300bd648ba356d398c95cbc11a45de73e4a68b5f9f553b39f1c27032
6
+ metadata.gz: 543e7cf9d0e3cb507861c3ec4190767c26f0df1a0858448334e7de46fff2dfe3c5579a03ef3cffed148fd453b5c03e5d9ebfc680dfe19db2e80d740ae6dde5ac
7
+ data.tar.gz: 8111036baa68ba2a81b4420d57a7b2e912490fe4ed79259f516702cfb39801b3e6c5ce950fba7430ac4601354d5c9c67093b1e1c93ef903ece18383af950d670
data/README.md CHANGED
@@ -38,15 +38,35 @@ The client provides with direct access to every API call as documented in the de
38
38
 
39
39
  ```rb
40
40
  # get a card to purchase
41
- card = client.reseller.shop_cards.first
41
+ card = client.cards.first
42
42
  # purchase the card for someone
43
- transaction = card.purchase(to_email: 'customer@example.com', shop_card_id: 1234)
43
+ transaction = card.purchase(to_email: 'customer@example.com')
44
44
  # load more details on the transaction
45
45
  transaction = transaction.reload
46
46
  # refund the transaction
47
47
  transaction.refund
48
48
  ```
49
49
 
50
+ ## Convenience methods
51
+
52
+ ### `client.cards`
53
+
54
+ Maps to `client.reseller.shop_cards`, allows for easier access and a less verbose DSL.
55
+
56
+ ### `card.purchase`
57
+
58
+ Maps to `client.partner.purchase.gift_card_direct` and passes along all the same parameters while automatically setting the `shop_card_id`.
59
+
60
+ ### `transaction.reload`
61
+
62
+ The purchase method returns an incomplete transaction object. This convenience methods
63
+ calls `client.reseller.transaction.find` passing along the transaction `id` and returns a
64
+ new `Gyft::Transaction` object.
65
+
66
+ ### `transaction.refund`
67
+
68
+ Maps to `client.reseller.transactions.refund` and automatically passes along the transaction `id`.
69
+
50
70
  ## API
51
71
 
52
72
  ### GET /health/check
@@ -271,3 +291,21 @@ Gyft::Transaction {
271
291
  :url => "https://staging.gyft.com/card/#/?c=...."
272
292
  }
273
293
  ```
294
+
295
+ ## Contributing
296
+
297
+ 1. **Fork** the repo on GitHub
298
+ 2. **Clone** the project to your own machine
299
+ 3. **Commit** changes to your own branch
300
+ 4. **Push** your work back up to your fork
301
+ 5. Submit a **Pull request** so that we can review your changes
302
+
303
+ ### Development
304
+
305
+ * `bundle install` to get dependencies
306
+ * `rake` to run tests
307
+ * `rake console` to run a local console with the library loaded
308
+
309
+ ## License
310
+
311
+ This library is released under the [MIT License](LICENSE).
@@ -1,2 +1,6 @@
1
1
  class Gyft::Card < OpenStruct
2
+ def purchase params = {}
3
+ params[:shop_card_id] = id
4
+ client.partner.purchase.gift_card_direct(params)
5
+ end
2
6
  end
@@ -4,8 +4,7 @@ require 'json'
4
4
 
5
5
  module Gyft
6
6
  class Client
7
- class Error < StandardError; end
8
- class ServerError < Error; end
7
+ class ServerError < StandardError; end
9
8
 
10
9
  ENDPOINTS = {
11
10
  'production' => 'api.gyft.com',
@@ -39,6 +38,10 @@ module Gyft
39
38
  http.use_ssl = true
40
39
  end
41
40
 
41
+ def cards
42
+ reseller.shop_cards
43
+ end
44
+
42
45
  def health
43
46
  Gyft::Client::Health.new(self)
44
47
  end
@@ -11,8 +11,11 @@ class Gyft::Client::Partner
11
11
  params = symbolize(params)
12
12
  options = extract(params, :to_email, :shop_card_id)
13
13
  options = merge(options, params, :reseller_reference, :notes, :first_name, :last_name, :gender, :birthday)
14
- result = @client.post("/partner/purchase/gift_card_direct", options)
15
- Gyft::Transaction.new(result)
14
+
15
+ transaction = @client.post("/partner/purchase/gift_card_direct", options)
16
+
17
+ transaction[:client] = @client
18
+ Gyft::Transaction.new(transaction)
16
19
  end
17
20
 
18
21
  private
@@ -6,23 +6,28 @@ class Gyft::Client::Reseller
6
6
 
7
7
  def shop_cards
8
8
  @client.get('/reseller/shop_cards').map do |card|
9
+ card[:client] = @client
9
10
  Gyft::Card.new(card)
10
11
  end
11
12
  end
12
13
 
13
14
  def categories
14
15
  @client.get('/reseller/categories')['details'].map do |category|
16
+ category[:client] = @client
15
17
  Gyft::Category.new(category)
16
18
  end
17
19
  end
18
20
 
19
21
  def merchants
20
22
  @client.get('/reseller/merchants')['details'].map do |merchant|
23
+ merchant[:client] = @client
21
24
  merchant = Gyft::Merchant.new(merchant)
22
25
  merchant.shop_cards = merchant.shop_cards.map do |card|
26
+ card[:client] = @client
23
27
  Gyft::Card.new(card)
24
28
  end
25
29
  merchant.categories = merchant.categories.map do |category|
30
+ category[:client] = @client
26
31
  Gyft::Category.new(category)
27
32
  end
28
33
  merchant
@@ -30,8 +35,9 @@ class Gyft::Client::Reseller
30
35
  end
31
36
 
32
37
  def account
33
- result = @client.get('/reseller/account')
34
- Gyft::Account.new(result)
38
+ account = @client.get('/reseller/account')
39
+ account[:client] = @client
40
+ Gyft::Account.new(account)
35
41
  end
36
42
 
37
43
  def transactions
@@ -5,30 +5,35 @@ class Gyft::Client::Transactions
5
5
  end
6
6
 
7
7
  def find id
8
- result = @client.get("/reseller/transaction/#{id}")
9
- Gyft::Transaction.new(result)
8
+ transaction = @client.get("/reseller/transaction/#{id}")
9
+ transaction[:client] = @client
10
+ Gyft::Transaction.new(transaction)
10
11
  end
11
12
 
12
13
  def all
13
14
  @client.get('/reseller/transactions').map do |transaction|
15
+ transaction[:client] = @client
14
16
  Gyft::Transaction.new(transaction)
15
17
  end
16
18
  end
17
19
 
18
20
  def first number_of_records
19
21
  @client.get("/reseller/transactions/first/#{number_of_records}").map do |transaction|
22
+ transaction[:client] = @client
20
23
  Gyft::Transaction.new(transaction)
21
24
  end
22
25
  end
23
26
 
24
27
  def last number_of_records
25
28
  @client.get("/reseller/transactions/last/#{number_of_records}").map do |transaction|
29
+ transaction[:client] = @client
26
30
  Gyft::Transaction.new(transaction)
27
31
  end
28
32
  end
29
33
 
30
34
  def refund id
31
- result = @client.post("/reseller/transaction/refund", id: id)
32
- Gyft::Refund.new(result)
35
+ transaction = @client.post("/reseller/transaction/refund", id: id)
36
+ transaction[:client] = @client
37
+ Gyft::Refund.new(transaction)
33
38
  end
34
39
  end
@@ -1,2 +1,9 @@
1
1
  class Gyft::Transaction < OpenStruct
2
+ def reload
3
+ client.reseller.transactions.find(id)
4
+ end
5
+
6
+ def refund
7
+ client.reseller.transactions.refund(id)
8
+ end
2
9
  end
@@ -1,3 +1,3 @@
1
1
  module Gyft
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristiano Betta