gyft 0.0.2 → 0.0.3

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: 00dbb14a4c26ddb4f896a49b20991d911ace9961
4
- data.tar.gz: c7ac360ff24ff8d4b4928cd144e1db4df36e3374
3
+ metadata.gz: 430c2c8154291101cc09ba954792337d3d81ec03
4
+ data.tar.gz: 2cc655c695a6b1808c3ae2bab91b1500dc933098
5
5
  SHA512:
6
- metadata.gz: 519a6fa76e89dc5d070585652334ad4ceb78618ea19d3feb9e1eb6d7586899324c35d3490e71b4d4b6e84668b9274a8b8e2b85fd7a64fbc4d0ae3a886667c072
7
- data.tar.gz: b478b953e428c936ef65367c77e8b167018b26174f465c0f2c9cad34576f4113f0fd79df77a29e5b137fcedb16575383a6576fd5dd7ee2c969d1b69091f24eda
6
+ metadata.gz: 82f72fb65b37d149546bea4bc5df1ebc2101579473472f2a541583f7c3149f32f9058a3b46a2998b7ba500e1f630541cc8585535cf9c59b91c3f61ba46813394
7
+ data.tar.gz: 6903ddb6c74b2bdaa0d3e1bd3923ce366377c3a75ca23ebc96bfadbe714319e40c953615300bd648ba356d398c95cbc11a45de73e4a68b5f9f553b39f1c27032
data/README.md CHANGED
@@ -34,6 +34,19 @@ client = Gyft::Client.new
34
34
  client.reseller.shop_cards # => [#<Gyft::Card id=123, merchant_id="123", ...>, ...]
35
35
  ```
36
36
 
37
+ The client provides with direct access to every API call as documented in the developer documentation. Additionally it also provides some convenience methods.
38
+
39
+ ```rb
40
+ # get a card to purchase
41
+ card = client.reseller.shop_cards.first
42
+ # purchase the card for someone
43
+ transaction = card.purchase(to_email: 'customer@example.com', shop_card_id: 1234)
44
+ # load more details on the transaction
45
+ transaction = transaction.reload
46
+ # refund the transaction
47
+ transaction.refund
48
+ ```
49
+
37
50
  ## API
38
51
 
39
52
  ### GET /health/check
@@ -161,7 +174,7 @@ Gyft::Account {
161
174
  Returns a list of all the transactions for the reseller.
162
175
 
163
176
  ```rb
164
- > transactions = client.reseller.transactions
177
+ > transactions = client.reseller.transactions.all
165
178
  [#<Gyft::Transaction id=123, type=1, amount=25.0, created_when=1469034701000>, ...]
166
179
  > transactions.first
167
180
  Gyft::Transaction {
@@ -177,7 +190,7 @@ Gyft::Transaction {
177
190
  Returns a limited list of recent transactions for the reseller.
178
191
 
179
192
  ```rb
180
- > transactions = client.reseller.transactions(last: 1)
193
+ > transactions = client.reseller.transactions.last(1)
181
194
  [#<Gyft::Transaction id=123, type=1, amount=25.0, created_when=1469034701000>]
182
195
  > transactions.first
183
196
  Gyft::Transaction {
@@ -193,7 +206,7 @@ Gyft::Transaction {
193
206
  Returns a limited list of initial transactions for the reseller.
194
207
 
195
208
  ```rb
196
- > transactions = client.reseller.transactions(first: 1)
209
+ > transactions = client.reseller.transactions.first(1)
197
210
  [#<Gyft::Transaction id=122, type=1, amount=25.0, created_when=1469034701000>]
198
211
  > transactions.first
199
212
  Gyft::Transaction {
@@ -209,7 +222,7 @@ Gyft::Transaction {
209
222
  Returns a full details for a sent transaction
210
223
 
211
224
  ```rb
212
- > client.transaction(123)
225
+ > client.transactions.find(123)
213
226
  Gyft::Transaction {
214
227
  :id => 123,
215
228
  :merchant_name => "Grotto",
@@ -224,3 +237,37 @@ Gyft::Transaction {
224
237
  :gift_created => 1469034701000
225
238
  }
226
239
  ```
240
+
241
+ ### POST /transaction/refund
242
+
243
+ Refund transaction and get card details.
244
+
245
+ ```rb
246
+ > client.transactions.refund(123)
247
+ Gyft::Refund {
248
+ :id => "OTlkOGM1...k5W",
249
+ :status => 0,
250
+
251
+ :gf_reseller_id => "abc123",
252
+ :gf_reseller_transaction_id => 123333,
253
+ :email => "client@example.com",
254
+ :gf_order_id => 123456,
255
+ :gf_order_detail_id => 345678,
256
+ :gf_gyfted_card_id => 678997,
257
+ :invalidated => false
258
+ }
259
+ ```
260
+
261
+ ### POST /partner/purchase/gift_card_direct
262
+
263
+ ```rb
264
+ > client.partner.purchase.gift_card_direct(
265
+ to_email: 'customer@example.com',
266
+ shop_card_id: 1234
267
+ )
268
+
269
+ Gyft::Transaction {
270
+ :id => 1250483,
271
+ :url => "https://staging.gyft.com/card/#/?c=...."
272
+ }
273
+ ```
@@ -2,8 +2,11 @@ require 'gyft/version'
2
2
  require 'gyft/client'
3
3
  require 'gyft/client/health'
4
4
  require 'gyft/client/reseller'
5
+ require 'gyft/client/partner'
6
+ require 'gyft/client/transactions'
5
7
  require 'gyft/card'
6
8
  require 'gyft/category'
7
9
  require 'gyft/merchant'
8
10
  require 'gyft/account'
9
11
  require 'gyft/transaction'
12
+ require 'gyft/refund'
@@ -47,11 +47,21 @@ module Gyft
47
47
  Gyft::Client::Reseller.new(self)
48
48
  end
49
49
 
50
- def get(path, params = {}, headers = {})
51
- uri, timestamp = uri_for(path, params)
50
+ def partner
51
+ Gyft::Client::Partner.new(self)
52
+ end
53
+
54
+ def get(path)
55
+ uri, timestamp = uri_for(path)
52
56
  message = Net::HTTP::Get.new(uri.request_uri)
53
57
  message['x-sig-timestamp'] = timestamp
54
- headers.each { |key, value| message[key] = value }
58
+ transmit(message)
59
+ end
60
+
61
+ def post(path, params = {})
62
+ uri, timestamp = uri_for(path, params)
63
+ message = Net::HTTP::Post.new(uri.request_uri)
64
+ message['x-sig-timestamp'] = timestamp
55
65
  transmit(message)
56
66
  end
57
67
 
@@ -60,10 +70,10 @@ module Gyft
60
70
  def uri_for(path, params = {})
61
71
  uri = URI("https://#{ENDPOINTS[environment]}/mashery/v1#{path}")
62
72
  sig, timestamp = signature
63
- uri.query = URI.encode_www_form({
73
+ uri.query = URI.encode_www_form(params.merge({
64
74
  api_key: api_key,
65
75
  sig: sig
66
- })
76
+ }))
67
77
  [uri, timestamp]
68
78
  end
69
79
 
@@ -0,0 +1,38 @@
1
+ class Gyft::Client::Partner
2
+ def initialize client
3
+ @client = client
4
+ end
5
+
6
+ def purchase
7
+ self
8
+ end
9
+
10
+ def gift_card_direct params = {}
11
+ params = symbolize(params)
12
+ options = extract(params, :to_email, :shop_card_id)
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)
16
+ end
17
+
18
+ private
19
+
20
+ def symbolize params
21
+ params.inject({}){|hash,(k,v)| hash[k.to_sym] = v; hash}
22
+ end
23
+
24
+ def extract params, *args
25
+ options = {}
26
+ args.each do |arg|
27
+ options[arg] = params.fetch(arg)
28
+ end
29
+ options
30
+ end
31
+
32
+ def merge options, params, *args
33
+ args.each do |arg|
34
+ options[arg] = params[arg] if params[arg]
35
+ end
36
+ options
37
+ end
38
+ end
@@ -1,6 +1,3 @@
1
-
2
- require 'awesome_print'
3
-
4
1
  class Gyft::Client::Reseller
5
2
 
6
3
  def initialize client
@@ -37,33 +34,11 @@ class Gyft::Client::Reseller
37
34
  Gyft::Account.new(result)
38
35
  end
39
36
 
40
- def transactions options = {}
41
- path = transactions_path_for(options)
42
-
43
- @client.get(path).map do |transaction|
44
- Gyft::Transaction.new(transaction)
45
- end
46
- end
47
-
48
- def transaction id
49
- result = @client.get("/reseller/transaction/#{id}")
50
- Gyft::Transaction.new(result)
37
+ def transactions
38
+ Gyft::Client::Transactions.new(@client)
51
39
  end
52
40
 
53
- private
54
-
55
- def transactions_path_for(options)
56
- last = options[:last]
57
- first = options[:first]
58
-
59
- path = begin
60
- if last && last > 0
61
- "/reseller/transactions/last/#{last}"
62
- elsif first && first > 0
63
- "/reseller/transactions/first/#{first}"
64
- else
65
- '/reseller/transactions'
66
- end
67
- end
41
+ def transaction
42
+ Gyft::Client::Transactions.new(@client)
68
43
  end
69
44
  end
@@ -0,0 +1,34 @@
1
+ class Gyft::Client::Transactions
2
+
3
+ def initialize client
4
+ @client = client
5
+ end
6
+
7
+ def find id
8
+ result = @client.get("/reseller/transaction/#{id}")
9
+ Gyft::Transaction.new(result)
10
+ end
11
+
12
+ def all
13
+ @client.get('/reseller/transactions').map do |transaction|
14
+ Gyft::Transaction.new(transaction)
15
+ end
16
+ end
17
+
18
+ def first number_of_records
19
+ @client.get("/reseller/transactions/first/#{number_of_records}").map do |transaction|
20
+ Gyft::Transaction.new(transaction)
21
+ end
22
+ end
23
+
24
+ def last number_of_records
25
+ @client.get("/reseller/transactions/last/#{number_of_records}").map do |transaction|
26
+ Gyft::Transaction.new(transaction)
27
+ end
28
+ end
29
+
30
+ def refund id
31
+ result = @client.post("/reseller/transaction/refund", id: id)
32
+ Gyft::Refund.new(result)
33
+ end
34
+ end
@@ -0,0 +1,2 @@
1
+ class Gyft::Refund < OpenStruct
2
+ end
@@ -1,3 +1,3 @@
1
1
  module Gyft
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristiano Betta
@@ -81,8 +81,11 @@ files:
81
81
  - lib/gyft/category.rb
82
82
  - lib/gyft/client.rb
83
83
  - lib/gyft/client/health.rb
84
+ - lib/gyft/client/partner.rb
84
85
  - lib/gyft/client/reseller.rb
86
+ - lib/gyft/client/transactions.rb
85
87
  - lib/gyft/merchant.rb
88
+ - lib/gyft/refund.rb
86
89
  - lib/gyft/transaction.rb
87
90
  - lib/gyft/version.rb
88
91
  - spec/gyft_spec.rb