stannp 0.3.0 → 0.6.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: 2b75837b9841497a819ff0ecc1540b75cafa29b16694255447eaa214418a4d59
4
+ data.tar.gz: '021308c33f745ec2f9d82209fed48ae58c49055f88fa1a25762d1fae7973848c'
5
5
  SHA512:
6
- metadata.gz: 5a8c1c3a9047377908c0726dac92833007c367816d0683deed3fec3d92bc5f468b9c2b17bc957501f334f53c7ca57e7bd1d1cf8d834ecb2beac627492ec4d9fb
7
- data.tar.gz: 992bb70c57042c83ca701a34cfb4cb843fe4f34484ee27d3eb4ff08196d980324d58dd536e05705edd4ddb23320a0a5aa2f52e2a12d87e1e34eb4d922e9b20bf
6
+ metadata.gz: 90edcb56fa0374f3a1a18b80d442329d3631e42a2a751977e46eaf92d414a092dd6af72945f0a72b4de43c07d0b3f9fa09ae4fd7abffff7be6720f43c6e2e0e6
7
+ data.tar.gz: 44cb149dbea1d00ee6106aef2a45ace349c52b9a84ee332cbbe3bd24965abe815b513fb551e0ed97e5b30d1d6838d284cc04ec4b7b59c3dd1da380b5391fe71f
data/CHANGELOG.md CHANGED
@@ -8,3 +8,12 @@
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
14
+
15
+ ## [0.5.0] - 2022-04-16
16
+ - Add support for the Letters API
17
+
18
+ ## [0.6.0] - 2022-04-21
19
+ - Add support for the Groups 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,21 @@ module Stannp
29
30
  AddressesResource.new(client: self)
30
31
  end
31
32
 
33
+ def postcards
34
+ PostcardsResource.new(client: self)
35
+ end
36
+
37
+ def letters
38
+ LettersResource.new(client: self)
39
+ end
40
+
41
+ def groups
42
+ GroupsResource.new(client: self)
43
+ end
44
+
32
45
  def connection
33
46
  @connection ||= Faraday.new do |conn|
47
+ conn.url_prefix = BASE_URL
34
48
  conn.request :json
35
49
  conn.response :json, content_type: 'application/json'
36
50
  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 Group < 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,6 +14,16 @@ module Stannp
14
14
  handle_response client.connection.post(url, body, headers)
15
15
  end
16
16
 
17
+ def url_for(path:, params: nil)
18
+ url = "#{path}?api_key=#{client.api_key}"
19
+ params&.each do |k, v|
20
+ next unless v
21
+
22
+ url += "&#{k}=#{v}"
23
+ end
24
+ url
25
+ end
26
+
17
27
  private
18
28
 
19
29
  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,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class GroupsResource < Resource
5
+ def list(offset: nil, limit: nil)
6
+ params = { offset: offset, limit: limit }
7
+ url = url_for(path: 'groups/list', params: params)
8
+ List.from_request(data: get_request(url).body['data'], type: Group)
9
+ end
10
+
11
+ def create(name:)
12
+ url = url_for(path: 'groups/new')
13
+ Group.new(post_request(url, body: { name: name }).body['data'])
14
+ end
15
+
16
+ def add_recipients(id:, recipient_ids:)
17
+ url = url_for(path: "groups/add/#{id}")
18
+ ids = recipient_ids.is_a?(Array) ? recipient_ids.join(',') : recipient_ids
19
+ post_request(url, body: { recipients: ids }).body['success']
20
+ end
21
+
22
+ def remove_recipients(id:, recipient_ids:)
23
+ url = url_for(path: "groups/remove/#{id}")
24
+ ids = recipient_ids.is_a?(Array) ? recipient_ids.join(',') : recipient_ids
25
+ post_request(url, body: { recipients: ids }).body['success']
26
+ end
27
+
28
+ def delete(id:)
29
+ url = url_for(path: "groups/delete/#{id}")
30
+ post_request(url, body: { id: id }).body['success']
31
+ end
32
+
33
+ def purge(id:, delete_recipients: false)
34
+ url = url_for(path: "groups/purge/#{id}")
35
+ post_request(url, body: { id: id, delete_recipients: delete_recipients }).body['success']
36
+ end
37
+ end
38
+ 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
@@ -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.6.0'
5
5
  end
data/lib/stannp.rb CHANGED
@@ -13,8 +13,15 @@ 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'
17
+ autoload :LettersResource, 'stannp/resources/letters'
18
+ autoload :GroupsResource, 'stannp/resources/groups'
16
19
  # objects
17
20
  autoload :User, 'stannp/objects/user'
18
21
  autoload :Recipient, 'stannp/objects/recipient'
19
22
  autoload :Receipt, 'stannp/objects/receipt'
23
+ autoload :Postcard, 'stannp/objects/postcard'
24
+ autoload :Letter, 'stannp/objects/letter'
25
+ autoload :Batch, 'stannp/objects/batch'
26
+ autoload :Group, 'stannp/objects/group'
20
27
  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.6.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-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -58,12 +58,19 @@ 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/group.rb
63
+ - lib/stannp/objects/letter.rb
64
+ - lib/stannp/objects/postcard.rb
61
65
  - lib/stannp/objects/receipt.rb
62
66
  - lib/stannp/objects/recipient.rb
63
67
  - lib/stannp/objects/user.rb
64
68
  - lib/stannp/resource.rb
65
69
  - lib/stannp/resources/account.rb
66
70
  - lib/stannp/resources/addresses.rb
71
+ - lib/stannp/resources/groups.rb
72
+ - lib/stannp/resources/letters.rb
73
+ - lib/stannp/resources/postcards.rb
67
74
  - lib/stannp/resources/recipients.rb
68
75
  - lib/stannp/resources/user.rb
69
76
  - lib/stannp/version.rb