stannp 0.1.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: df463198452eace393468c01970f5a2d5f0aca063bfebd9e98a059b006525e66
4
- data.tar.gz: c0e810b647919ca53513ccb0d35010aeb5afeed348a2c2325d2cdde4ed658fd3
3
+ metadata.gz: d5cf8e8da25fd4bf0f3130533712a0d1a71e6d7cc9187b47fd9fc4643e5856cc
4
+ data.tar.gz: 8cbc6fd50818dbf95b2ffc7f34ec2e71d81b90b70cd81873a5c23a8d9f2d0f1e
5
5
  SHA512:
6
- metadata.gz: f84d3718a853fda778d709769141be754c250f99ee65de980307a98fbf1133b7b68f2d9e8b568007aaf9a4c88684189f38f9714002b6d50ea4c6ba58fc40c1ca
7
- data.tar.gz: 7a5a4e153c5822dcac9888b98bf7560ea7c76895f88fe0df5022596ff4edbe1667a5d09413916370f138b1e80f84bbb53a4944c973248a0fea6ea6f54cb7299f
6
+ metadata.gz: ceb18058cc55aa19e3a69ef61ddc50dbc40186fe511b0ece19194cc3f3e13ccb21c02f85bd48b6ceb1224659ef23df0ca2fc97491a0bd7124239333d4c870db7
7
+ data.tar.gz: 65ebaea8d56f197e89a8e4bdb4d29c46444dcb6c03541da765e8b7932514771b800ea4bd6895e77ac18ad5dcad9184fa683a8a298804d314658d2a5d47182cf0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
- ## [Unreleased]
1
+ ## [0.1.0] - 2022-04-10
2
+ - Add the Recipients API
3
+ - Add the User API
2
4
 
3
- ## [0.1.0] - 2022-04-09
5
+ ## [0.2.0] - 2022-04-11
6
+ - Add support for the complete Account API
4
7
 
5
- - Initial release
8
+ ## [0.3.0] - 2022-04-11
9
+ - Add support for recipient upload
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)
@@ -25,8 +26,17 @@ module Stannp
25
26
  RecipientsResource.new(client: self)
26
27
  end
27
28
 
29
+ def addresses
30
+ AddressesResource.new(client: self)
31
+ end
32
+
33
+ def postcards
34
+ PostcardsResource.new(client: self)
35
+ end
36
+
28
37
  def connection
29
38
  @connection ||= Faraday.new do |conn|
39
+ conn.url_prefix = BASE_URL
30
40
  conn.request :json
31
41
  conn.response :json, content_type: 'application/json'
32
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Receipt < Object; end
5
+ end
@@ -14,12 +14,8 @@ module Stannp
14
14
  handle_response client.connection.post(url, body, headers)
15
15
  end
16
16
 
17
- def patch_request(url, body:, headers: {})
18
- handle_response client.connection.patch(url, body, headers)
19
- end
20
-
21
- def put_request(url, body:, headers: {})
22
- handle_response client.connection.put(url, body, headers)
17
+ def url_for(path:)
18
+ "#{path}?api_key=#{client.api_key}"
23
19
  end
24
20
 
25
21
  private
@@ -3,8 +3,14 @@
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
+
10
+ def top_up(amount:)
11
+ url = url_for(path: 'accounts/topup')
12
+ url = post_request(url, body: { net: amount.to_f.to_s }).body['data']['receipt_pdf']
13
+ Stannp::Receipt.new(url: url)
14
+ end
9
15
  end
10
16
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class AddressesResource < Resource
5
+ def validate(attributes:)
6
+ url = url_for(path: 'addresses/validate')
7
+ post_request(url, body: attributes).body['data']['is_valid']
8
+ end
9
+ end
10
+ 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
@@ -35,5 +35,11 @@ module Stannp
35
35
 
36
36
  raise e
37
37
  end
38
+
39
+ def import(group_id:, file:, options: {})
40
+ url = url_for(path: 'recipients/import')
41
+ body = { group_id: group_id, file: file }.merge(options)
42
+ post_request(url, body: body).body['success']
43
+ end
38
44
  end
39
45
  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.1.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/stannp.rb CHANGED
@@ -12,7 +12,11 @@ module Stannp
12
12
  autoload :AccountResource, 'stannp/resources/account'
13
13
  autoload :UserResource, 'stannp/resources/user'
14
14
  autoload :RecipientsResource, 'stannp/resources/recipients'
15
+ autoload :AddressesResource, 'stannp/resources/addresses'
16
+ autoload :PostcardsResource, 'stannp/resources/postcards'
15
17
  # objects
16
18
  autoload :User, 'stannp/objects/user'
17
19
  autoload :Recipient, 'stannp/objects/recipient'
20
+ autoload :Receipt, 'stannp/objects/receipt'
21
+ autoload :Postcard, 'stannp/objects/postcard'
18
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.1.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-10 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,10 +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
62
+ - lib/stannp/objects/receipt.rb
61
63
  - lib/stannp/objects/recipient.rb
62
64
  - lib/stannp/objects/user.rb
63
65
  - lib/stannp/resource.rb
64
66
  - lib/stannp/resources/account.rb
67
+ - lib/stannp/resources/addresses.rb
68
+ - lib/stannp/resources/postcards.rb
65
69
  - lib/stannp/resources/recipients.rb
66
70
  - lib/stannp/resources/user.rb
67
71
  - lib/stannp/version.rb