stannp 0.2.0 → 0.5.0

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
  SHA256:
3
- metadata.gz: 59a7326c7fc932044cc7706a6e13769012cc269b253efa3ec51dae2b7c2517ea
4
- data.tar.gz: f5cb65cc496bbe21d4657a65053af6518fc812a573590648a5ccb2949e23ce02
3
+ metadata.gz: bff3ab1efdd21197064698fddde52daa93d9c4231d9d07ecc1d77be3e654c3d9
4
+ data.tar.gz: '059d4ec23e07c853a2c0134f2c0ecbecd05dc0ee174c2db538614f7954db24a1'
5
5
  SHA512:
6
- metadata.gz: cb4f1277029da2883fc36eea3e5ba72ba7b61d29fe10580f69d98894669952d6581d3208933d5c1ef67934a14ec4881ec194776e83e2a617da1930bb964466c4
7
- data.tar.gz: 882d0899a9beaaf8877bf944645e76fe3f32c208630da4700e5b4aa7dc26a5a02e0e7c5cbab0aa6b2f98379cc77117ce5a27cd72ef220b98307946b27d5da846
6
+ metadata.gz: c280a7cfb8cc8199ead8628cf599556e19ffd06298507630211e2a0e4c062a2f389bb54ecc010635e2fec148ebcdfcbecb09da9f5c3285097e2f6bd9bd609a08
7
+ data.tar.gz: 33ea9120a90755f163ad2b4597679da35c28b99d9a73550498259a558fb3b46d1efd582e434e586c7bf34afb4dcf9976bf7552ed2711bce7d9159277142a63c7
data/CHANGELOG.md CHANGED
@@ -4,3 +4,13 @@
4
4
 
5
5
  ## [0.2.0] - 2022-04-11
6
6
  - Add support for the complete Account API
7
+
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
14
+
15
+ ## [0.5.0] - 2022-04-16
16
+ - Add support for the Letters 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,21 @@ 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
+
37
+ def letters
38
+ LettersResource.new(client: self)
39
+ end
40
+
28
41
  def connection
29
42
  @connection ||= Faraday.new do |conn|
43
+ conn.url_prefix = BASE_URL
30
44
  conn.request :json
31
45
  conn.response :json, content_type: 'application/json'
32
46
  conn.adapter adapter, stubs
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Batch < Object; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Letter < Object; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Postcard < 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,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
@@ -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,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class LettersResource < Resource
5
+ def create(attributes:)
6
+ url = url_for(path: 'letters/create')
7
+ Letter.new(post_request(url, body: attributes).body['data'])
8
+ end
9
+
10
+ def post(attributes:)
11
+ url = url_for(path: 'letters/post')
12
+ Letter.new(post_request(url, body: attributes).body['data'])
13
+ end
14
+
15
+ def get(id:)
16
+ url = url_for(path: "letters/get/#{id}")
17
+ Letter.new(get_request(url).body['data'])
18
+ end
19
+
20
+ def cancel(id:)
21
+ url = url_for(path: 'letters/cancel')
22
+ post_request(url, body: { id: id }).body['success']
23
+ end
24
+
25
+ def batch(attributes:)
26
+ url = url_for(path: 'letters/batch')
27
+ Batch.new(post_request(url, body: attributes).body['data'])
28
+ end
29
+ end
30
+ 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.2.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/stannp.rb CHANGED
@@ -12,8 +12,14 @@ 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'
17
+ autoload :LettersResource, 'stannp/resources/letters'
15
18
  # objects
16
19
  autoload :User, 'stannp/objects/user'
17
20
  autoload :Recipient, 'stannp/objects/recipient'
18
21
  autoload :Receipt, 'stannp/objects/receipt'
22
+ autoload :Postcard, 'stannp/objects/postcard'
23
+ autoload :Letter, 'stannp/objects/letter'
24
+ autoload :Batch, 'stannp/objects/batch'
19
25
  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.2.0
4
+ version: 0.5.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,11 +58,17 @@ files:
58
58
  - lib/stannp/error.rb
59
59
  - lib/stannp/list.rb
60
60
  - lib/stannp/object.rb
61
+ - lib/stannp/objects/batch.rb
62
+ - lib/stannp/objects/letter.rb
63
+ - lib/stannp/objects/postcard.rb
61
64
  - lib/stannp/objects/receipt.rb
62
65
  - lib/stannp/objects/recipient.rb
63
66
  - lib/stannp/objects/user.rb
64
67
  - lib/stannp/resource.rb
65
68
  - lib/stannp/resources/account.rb
69
+ - lib/stannp/resources/addresses.rb
70
+ - lib/stannp/resources/letters.rb
71
+ - lib/stannp/resources/postcards.rb
66
72
  - lib/stannp/resources/recipients.rb
67
73
  - lib/stannp/resources/user.rb
68
74
  - lib/stannp/version.rb