stannp 0.5.0 → 0.6.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: bff3ab1efdd21197064698fddde52daa93d9c4231d9d07ecc1d77be3e654c3d9
4
- data.tar.gz: '059d4ec23e07c853a2c0134f2c0ecbecd05dc0ee174c2db538614f7954db24a1'
3
+ metadata.gz: 2b75837b9841497a819ff0ecc1540b75cafa29b16694255447eaa214418a4d59
4
+ data.tar.gz: '021308c33f745ec2f9d82209fed48ae58c49055f88fa1a25762d1fae7973848c'
5
5
  SHA512:
6
- metadata.gz: c280a7cfb8cc8199ead8628cf599556e19ffd06298507630211e2a0e4c062a2f389bb54ecc010635e2fec148ebcdfcbecb09da9f5c3285097e2f6bd9bd609a08
7
- data.tar.gz: 33ea9120a90755f163ad2b4597679da35c28b99d9a73550498259a558fb3b46d1efd582e434e586c7bf34afb4dcf9976bf7552ed2711bce7d9159277142a63c7
6
+ metadata.gz: 90edcb56fa0374f3a1a18b80d442329d3631e42a2a751977e46eaf92d414a092dd6af72945f0a72b4de43c07d0b3f9fa09ae4fd7abffff7be6720f43c6e2e0e6
7
+ data.tar.gz: 44cb149dbea1d00ee6106aef2a45ace349c52b9a84ee332cbbe3bd24965abe815b513fb551e0ed97e5b30d1d6838d284cc04ec4b7b59c3dd1da380b5391fe71f
data/CHANGELOG.md CHANGED
@@ -14,3 +14,6 @@
14
14
 
15
15
  ## [0.5.0] - 2022-04-16
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
@@ -38,6 +38,10 @@ module Stannp
38
38
  LettersResource.new(client: self)
39
39
  end
40
40
 
41
+ def groups
42
+ GroupsResource.new(client: self)
43
+ end
44
+
41
45
  def connection
42
46
  @connection ||= Faraday.new do |conn|
43
47
  conn.url_prefix = BASE_URL
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stannp
4
+ class Group < Object; end
5
+ end
@@ -14,8 +14,14 @@ 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}"
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
19
25
  end
20
26
 
21
27
  private
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stannp
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/stannp.rb CHANGED
@@ -15,6 +15,7 @@ module Stannp
15
15
  autoload :AddressesResource, 'stannp/resources/addresses'
16
16
  autoload :PostcardsResource, 'stannp/resources/postcards'
17
17
  autoload :LettersResource, 'stannp/resources/letters'
18
+ autoload :GroupsResource, 'stannp/resources/groups'
18
19
  # objects
19
20
  autoload :User, 'stannp/objects/user'
20
21
  autoload :Recipient, 'stannp/objects/recipient'
@@ -22,4 +23,5 @@ module Stannp
22
23
  autoload :Postcard, 'stannp/objects/postcard'
23
24
  autoload :Letter, 'stannp/objects/letter'
24
25
  autoload :Batch, 'stannp/objects/batch'
26
+ autoload :Group, 'stannp/objects/group'
25
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.5.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-16 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
@@ -59,6 +59,7 @@ files:
59
59
  - lib/stannp/list.rb
60
60
  - lib/stannp/object.rb
61
61
  - lib/stannp/objects/batch.rb
62
+ - lib/stannp/objects/group.rb
62
63
  - lib/stannp/objects/letter.rb
63
64
  - lib/stannp/objects/postcard.rb
64
65
  - lib/stannp/objects/receipt.rb
@@ -67,6 +68,7 @@ files:
67
68
  - lib/stannp/resource.rb
68
69
  - lib/stannp/resources/account.rb
69
70
  - lib/stannp/resources/addresses.rb
71
+ - lib/stannp/resources/groups.rb
70
72
  - lib/stannp/resources/letters.rb
71
73
  - lib/stannp/resources/postcards.rb
72
74
  - lib/stannp/resources/recipients.rb