stannp 0.3.0 → 0.4.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: cfc91d10039a3c87a7c4e8725a764dce523dd9f26ff814a20a39757bdb86108d
4
- data.tar.gz: 153a1c9b0a9a6fc9cfc23a4fa630ba144a01712027dc4f39865199c5eb463875
3
+ metadata.gz: d5cf8e8da25fd4bf0f3130533712a0d1a71e6d7cc9187b47fd9fc4643e5856cc
4
+ data.tar.gz: 8cbc6fd50818dbf95b2ffc7f34ec2e71d81b90b70cd81873a5c23a8d9f2d0f1e
5
5
  SHA512:
6
- metadata.gz: 5a8c1c3a9047377908c0726dac92833007c367816d0683deed3fec3d92bc5f468b9c2b17bc957501f334f53c7ca57e7bd1d1cf8d834ecb2beac627492ec4d9fb
7
- data.tar.gz: 992bb70c57042c83ca701a34cfb4cb843fe4f34484ee27d3eb4ff08196d980324d58dd536e05705edd4ddb23320a0a5aa2f52e2a12d87e1e34eb4d922e9b20bf
6
+ metadata.gz: ceb18058cc55aa19e3a69ef61ddc50dbc40186fe511b0ece19194cc3f3e13ccb21c02f85bd48b6ceb1224659ef23df0ca2fc97491a0bd7124239333d4c870db7
7
+ data.tar.gz: 65ebaea8d56f197e89a8e4bdb4d29c46444dcb6c03541da765e8b7932514771b800ea4bd6895e77ac18ad5dcad9184fa683a8a298804d314658d2a5d47182cf0
data/CHANGELOG.md CHANGED
@@ -8,3 +8,6 @@
8
8
  ## [0.3.0] - 2022-04-11
9
9
  - Add support for recipient upload
10
10
  - Add the Addresses API
11
+
12
+ ## [0.4.0] - 2022-04-16
13
+ - Add support for the Postcards API
data/lib/stannp/client.rb CHANGED
@@ -5,6 +5,7 @@ require 'faraday_middleware'
5
5
 
6
6
  module Stannp
7
7
  class Client
8
+ BASE_URL = 'https://dash.stannp.com/api/v1'
8
9
  attr_reader :api_key, :adapter
9
10
 
10
11
  def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
@@ -29,8 +30,13 @@ module Stannp
29
30
  AddressesResource.new(client: self)
30
31
  end
31
32
 
33
+ def postcards
34
+ PostcardsResource.new(client: self)
35
+ end
36
+
32
37
  def connection
33
38
  @connection ||= Faraday.new do |conn|
39
+ conn.url_prefix = BASE_URL
34
40
  conn.request :json
35
41
  conn.response :json, content_type: 'application/json'
36
42
  conn.adapter adapter, stubs
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Postcard < Object; end
5
+ end
@@ -14,6 +14,10 @@ module Stannp
14
14
  handle_response client.connection.post(url, body, headers)
15
15
  end
16
16
 
17
+ def url_for(path:)
18
+ "#{path}?api_key=#{client.api_key}"
19
+ end
20
+
17
21
  private
18
22
 
19
23
  attr_reader :client
@@ -3,12 +3,12 @@
3
3
  module Stannp
4
4
  class AccountResource < Resource
5
5
  def balance
6
- url = "https://dash.stannp.com/api/v1/accounts/balance?api_key=#{client.api_key}}"
6
+ url = url_for(path: 'accounts/balance')
7
7
  get_request(url).body['data']['balance']
8
8
  end
9
9
 
10
10
  def top_up(amount:)
11
- url = "https://dash.stannp.com/api/v1/accounts/topup?api_key=#{client.api_key}}"
11
+ url = url_for(path: 'accounts/topup')
12
12
  url = post_request(url, body: { net: amount.to_f.to_s }).body['data']['receipt_pdf']
13
13
  Stannp::Receipt.new(url: url)
14
14
  end
@@ -3,7 +3,7 @@
3
3
  module Stannp
4
4
  class AddressesResource < Resource
5
5
  def validate(attributes:)
6
- url = "https://dash.stannp.com/api/v1/addresses/validate?api_key=#{client.api_key}"
6
+ url = url_for(path: 'addresses/validate')
7
7
  post_request(url, body: attributes).body['data']['is_valid']
8
8
  end
9
9
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class PostcardsResource < Resource
5
+ def create(attributes:)
6
+ url = url_for(path: 'postcards/create')
7
+ Postcard.new(post_request(url, body: attributes).body['data'])
8
+ end
9
+
10
+ def get(id:)
11
+ url = url_for(path: "postcards/get/#{id}")
12
+ Postcard.new(get_request(url).body['data'])
13
+ end
14
+
15
+ def cancel(id:)
16
+ url = url_for(path: 'postcards/cancel')
17
+ post_request(url, body: { id: id }).body['success']
18
+ end
19
+ end
20
+ end
@@ -4,28 +4,28 @@ module Stannp
4
4
  class RecipientsResource < Resource
5
5
  def list(group_id: nil)
6
6
  id = group_id ? "/#{group_id}" : ''
7
- url = "https://dash.stannp.com/api/v1/recipients/list#{id}?api_key=#{client.api_key}"
7
+ url = url_for(path: "recipients/list#{id}")
8
8
  List.from_request(data: get_request(url).body['data'], type: Recipient)
9
9
  end
10
10
 
11
11
  def get(id:)
12
- url = "https://dash.stannp.com/api/v1/recipients/get/#{id}?api_key=#{client.api_key}"
12
+ url = url_for(path: "recipients/get/#{id}")
13
13
  Recipient.new(get_request(url).body['data'])
14
14
  end
15
15
 
16
16
  def create(attributes:)
17
- url = "https://dash.stannp.com/api/v1/recipients/new?api_key=#{client.api_key}"
17
+ url = url_for(path: 'recipients/new')
18
18
  Recipient.new(post_request(url, body: attributes).body['data'])
19
19
  end
20
20
 
21
21
  def delete(id:)
22
- url = "https://dash.stannp.com/api/v1/recipients/delete?api_key=#{client.api_key}"
22
+ url = url_for(path: 'recipients/delete')
23
23
  post_request(url, body: { id: id.to_i })
24
24
  true
25
25
  end
26
26
 
27
27
  def delete_all
28
- url = "https://dash.stannp.com/api/v1/recipients/deleteAll?api_key=#{client.api_key}"
28
+ url = url_for(path: 'recipients/deleteAll')
29
29
  post_request(url, body: { delete_all: true })
30
30
  true
31
31
  rescue Stannp::Error => e
@@ -37,7 +37,7 @@ module Stannp
37
37
  end
38
38
 
39
39
  def import(group_id:, file:, options: {})
40
- url = "https://dash.stannp.com/api/v1/recipients/import?api_key=#{client.api_key}"
40
+ url = url_for(path: 'recipients/import')
41
41
  body = { group_id: group_id, file: file }.merge(options)
42
42
  post_request(url, body: body).body['success']
43
43
  end
@@ -3,7 +3,7 @@
3
3
  module Stannp
4
4
  class UserResource < Resource
5
5
  def get
6
- url = "https://dash.stannp.com/api/v1/users/me?api_key=#{client.api_key}"
6
+ url = url_for(path: 'users/me')
7
7
  User.new(get_request(url).body['data'])
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stannp
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/stannp.rb CHANGED
@@ -13,8 +13,10 @@ module Stannp
13
13
  autoload :UserResource, 'stannp/resources/user'
14
14
  autoload :RecipientsResource, 'stannp/resources/recipients'
15
15
  autoload :AddressesResource, 'stannp/resources/addresses'
16
+ autoload :PostcardsResource, 'stannp/resources/postcards'
16
17
  # objects
17
18
  autoload :User, 'stannp/objects/user'
18
19
  autoload :Recipient, 'stannp/objects/recipient'
19
20
  autoload :Receipt, 'stannp/objects/receipt'
21
+ autoload :Postcard, 'stannp/objects/postcard'
20
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stannp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-p-jones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -58,12 +58,14 @@ files:
58
58
  - lib/stannp/error.rb
59
59
  - lib/stannp/list.rb
60
60
  - lib/stannp/object.rb
61
+ - lib/stannp/objects/postcard.rb
61
62
  - lib/stannp/objects/receipt.rb
62
63
  - lib/stannp/objects/recipient.rb
63
64
  - lib/stannp/objects/user.rb
64
65
  - lib/stannp/resource.rb
65
66
  - lib/stannp/resources/account.rb
66
67
  - lib/stannp/resources/addresses.rb
68
+ - lib/stannp/resources/postcards.rb
67
69
  - lib/stannp/resources/recipients.rb
68
70
  - lib/stannp/resources/user.rb
69
71
  - lib/stannp/version.rb