seven_api 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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/ruby-client.iml +16 -4
  3. data/README.md +2 -2
  4. data/doc/{Sms77 → SevenApi}/Client.html +222 -222
  5. data/doc/{Sms77 → SevenApi}/Contacts/Action.html +130 -130
  6. data/doc/{Sms77 → SevenApi}/Contacts.html +125 -125
  7. data/doc/{Sms77 → SevenApi}/Endpoint.html +186 -186
  8. data/doc/{Sms77 → SevenApi}/Hooks/Action.html +130 -130
  9. data/doc/{Sms77 → SevenApi}/Hooks/EventType.html +145 -145
  10. data/doc/{Sms77 → SevenApi}/Hooks/RequestMethod.html +130 -130
  11. data/doc/{Sms77 → SevenApi}/Hooks/Validator.html +582 -582
  12. data/doc/{Sms77 → SevenApi}/Hooks.html +125 -125
  13. data/doc/{Sms77 → SevenApi}/Journal/Type.html +135 -135
  14. data/doc/{Sms77 → SevenApi}/Journal/Validator.html +380 -380
  15. data/doc/{Sms77 → SevenApi}/Journal.html +125 -125
  16. data/doc/{Sms77 → SevenApi}/Lookup/Type.html +135 -135
  17. data/doc/{Sms77 → SevenApi}/Lookup.html +125 -125
  18. data/doc/{Sms77 → SevenApi}/Resource.html +857 -857
  19. data/doc/{Sms77 → SevenApi}/Resources/Analytics.html +260 -260
  20. data/doc/{Sms77 → SevenApi}/Resources/Balance.html +243 -243
  21. data/doc/{Sms77 → SevenApi}/Resources/Contacts.html +445 -445
  22. data/doc/{Sms77 → SevenApi}/Resources/Hooks.html +453 -453
  23. data/doc/{Sms77 → SevenApi}/Resources/Journal.html +258 -258
  24. data/doc/{Sms77 → SevenApi}/Resources/Lookup.html +535 -535
  25. data/doc/{Sms77 → SevenApi}/Resources/Pricing.html +260 -260
  26. data/doc/{Sms77 → SevenApi}/Resources/Sms.html +258 -258
  27. data/doc/{Sms77 → SevenApi}/Resources/Status.html +258 -258
  28. data/doc/{Sms77 → SevenApi}/Resources/Subaccounts.html +645 -645
  29. data/doc/{Sms77 → SevenApi}/Resources/ValidateForVoice.html +258 -258
  30. data/doc/{Sms77 → SevenApi}/Resources/Voice.html +258 -258
  31. data/doc/SevenApi/Resources.html +128 -0
  32. data/doc/{Sms77 → SevenApi}/Sms/Type.html +125 -125
  33. data/doc/{Sms77 → SevenApi}/Sms.html +125 -125
  34. data/doc/{Sms77 → SevenApi}/Subaccounts/Action.html +140 -140
  35. data/doc/SevenApi/Subaccounts/Validator.html +490 -0
  36. data/doc/{Sms77 → SevenApi}/Subaccounts.html +125 -125
  37. data/doc/{Sms77 → SevenApi}/Util.html +993 -993
  38. data/doc/{Sms77.html → SevenApi.html} +145 -145
  39. data/doc/_index.html +443 -443
  40. data/doc/class_list.html +51 -51
  41. data/doc/css/full_list.css +58 -58
  42. data/doc/css/style.css +497 -497
  43. data/doc/file.README.html +110 -111
  44. data/doc/file_list.html +56 -56
  45. data/doc/frames.html +17 -17
  46. data/doc/index.html +110 -111
  47. data/doc/js/app.js +314 -314
  48. data/doc/js/full_list.js +216 -216
  49. data/doc/js/jquery.js +3 -3
  50. data/doc/method_list.html +563 -563
  51. data/doc/top-level-namespace.html +109 -109
  52. data/lib/seven_api/client.rb +2 -0
  53. data/lib/seven_api/contacts.rb +0 -5
  54. data/lib/seven_api/endpoint.rb +5 -0
  55. data/lib/seven_api/hooks.rb +1 -0
  56. data/lib/seven_api/lookup.rb +1 -0
  57. data/lib/seven_api/numbers.rb +9 -0
  58. data/lib/seven_api/paginated.rb +10 -0
  59. data/lib/seven_api/rcs.rb +9 -0
  60. data/lib/seven_api/resource.rb +8 -3
  61. data/lib/seven_api/resources/analytics.rb +38 -5
  62. data/lib/seven_api/resources/balance.rb +2 -2
  63. data/lib/seven_api/resources/contacts.rb +36 -18
  64. data/lib/seven_api/resources/groups.rb +57 -0
  65. data/lib/seven_api/resources/hooks.rb +1 -1
  66. data/lib/seven_api/resources/journal.rb +1 -1
  67. data/lib/seven_api/resources/lookup.rb +36 -20
  68. data/lib/seven_api/resources/numbers.rb +70 -0
  69. data/lib/seven_api/resources/pricing.rb +1 -1
  70. data/lib/seven_api/resources/rcs.rb +39 -0
  71. data/lib/seven_api/resources/sms.rb +1 -1
  72. data/lib/seven_api/resources/status.rb +1 -1
  73. data/lib/seven_api/resources/subaccounts.rb +5 -5
  74. data/lib/seven_api/resources/validate_for_voice.rb +1 -1
  75. data/lib/seven_api/resources/voice.rb +1 -1
  76. data/lib/seven_api/version.rb +1 -1
  77. data/seven_api.gemspec +5 -5
  78. data/spec/seven_api/analytics_spec.rb +49 -0
  79. data/spec/seven_api/balance_spec.rb +8 -2
  80. data/spec/seven_api/contacts_spec.rb +52 -81
  81. data/spec/seven_api/groups_spec.rb +74 -0
  82. data/spec/seven_api/lookup_spec.rb +51 -33
  83. data/spec/seven_api/numbers_spec.rb +135 -0
  84. data/spec/seven_api/rcs_spec.rb +99 -0
  85. data/spec/seven_api/sms_spec.rb +2 -2
  86. data/spec/seven_api/voice_spec.rb +2 -2
  87. data/spec/spec_helper.rb +8 -17
  88. metadata +64 -50
  89. data/doc/Sms77/Resources.html +0 -128
  90. data/doc/Sms77/Subaccounts/Validator.html +0 -490
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resource'
4
+
5
+ # This module exposes the methods for communicating with the API endpoint /numbers.
6
+ module SevenApi::Resources
7
+ class Groups < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::NUMBERS
9
+ @http_methods = {
10
+ :active => :get,
11
+ :available => :get,
12
+ :order => :post,
13
+ :one => :get,
14
+ :update => :patch,
15
+ }
16
+
17
+ # Retrieve active phone numbers
18
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#active-numbers
19
+ # @return [Array]
20
+ def active
21
+ request({}, {}, '/active')
22
+ end
23
+
24
+
25
+ # Retrieve available phone numbers
26
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#available-numbers
27
+ # @return [Hash]
28
+ def available
29
+ request(params, {}, '/available')
30
+ end
31
+
32
+ # Order a phone number
33
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#order-a-number
34
+ # @param number [String]
35
+ # @param payment_interval [String]
36
+ # @return [Hash]
37
+ def order(number, payment_interval = PaymentInterval.ASCENDING)
38
+ payload = {
39
+ number => number,
40
+ payment_interval => payment_interval,
41
+ }
42
+ request(payload, {}, '/order')
43
+ end
44
+
45
+ # Delete a number
46
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#delete-number
47
+ # @param number [String]
48
+ # @return [Hash]
49
+ def delete(number, delete_immediately = false)
50
+ request({}, {delete_immediately => delete_immediately}, "/active/#{number}")
51
+ end
52
+
53
+ # Retrieve a number
54
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#get-number
55
+ # @param number [String]
56
+ # @return [Hash]
57
+ def one(number)
58
+ request({}, {}, "/active/#{number}")
59
+ end
60
+
61
+ # Update a number
62
+ # read more: https://docs.seven.io/en/rest-api/endpoints/numbers#update-number
63
+ # @param number [String]
64
+ # @param params [Hash]
65
+ # @return [Hash]
66
+ def update(number, params)
67
+ request(params, {}, "/active/#{number}")
68
+ end
69
+ end
70
+ end
@@ -11,7 +11,7 @@ module SevenApi::Resources
11
11
  }
12
12
 
13
13
  # Retrieve pricing
14
- # read more: https://www.seven.io/en/docs/gateway/http-api/pricing/
14
+ # read more: https://docs.seven.io/en/rest-api/endpoints/account#prices
15
15
  # @param params [Hash]
16
16
  # @return [Hash,String]
17
17
  def retrieve(params = {})
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resource'
4
+
5
+ # This module exposes the methods for communicating with the API endpoint /rcs.
6
+ module SevenApi::Resources
7
+ class Rcs < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::RCS
9
+ @http_methods = {
10
+ :delete => :delete,
11
+ :dispatch => :post,
12
+ :event => :post
13
+ }
14
+
15
+ # Send RCS
16
+ # read more: https://docs.seven.io/en/rest-api/endpoints/rcs#send-rcs
17
+ # @param params [Hash]
18
+ # @return [Hash]
19
+ def dispatch(params)
20
+ request(params, {}, '/messages')
21
+ end
22
+
23
+ # Delete scheduled RCS
24
+ # read more: https://docs.seven.io/en/rest-api/endpoints/rcs#delete-rcs
25
+ # @param params [Hash]
26
+ # @return [Hash]
27
+ def delete(params)
28
+ request({}, {}, "/messages/#{params[:id]}")
29
+ end
30
+
31
+ # Send Event
32
+ # read more: https://docs.seven.io/en/rest-api/endpoints/rcs#events
33
+ # @param params [Hash]
34
+ # @return [Hash]
35
+ def event(params)
36
+ request(params, {}, '/events')
37
+ end
38
+ end
39
+ end
@@ -11,7 +11,7 @@ module SevenApi::Resources
11
11
  }
12
12
 
13
13
  # Send SMS
14
- # read more: https://www.seven.io/en/docs/gateway/http-api/sms-dispatch/
14
+ # read more: https://docs.seven.io/en/rest-api/endpoints/sms#send-sms
15
15
  # @param params [Hash]
16
16
  # @return [Integer,String,Hash]
17
17
  def retrieve(params)
@@ -11,7 +11,7 @@ module SevenApi::Resources
11
11
  }
12
12
 
13
13
  # Retrieve delivery report for a SMS
14
- # read more: https://www.seven.io/en/docs/gateway/http-api/status-reports/#query-delivery-reports
14
+ # read more: https://docs.seven.io/en/rest-api/endpoints/status-reports#query-status-reports
15
15
  # @param params [Hash]
16
16
  # @return [String]
17
17
  def retrieve(params)
@@ -16,7 +16,7 @@ module SevenApi::Resources
16
16
  }
17
17
 
18
18
  # Create a subaccount
19
- # read more: https://www.seven.io/en/docs/gateway/http-api/subaccounts/#create-subaccount
19
+ # read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#create-subaccount
20
20
  # @param params [Hash]
21
21
  # @return [Hash]
22
22
  def create(params)
@@ -26,7 +26,7 @@ module SevenApi::Resources
26
26
  end
27
27
 
28
28
  # Delete a subaccount
29
- # read more: https://www.seven.io/en/docs/gateway/http-api/subaccounts/#delete-subaccount
29
+ # read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#delete-a-subaccount
30
30
  # @param params [Hash]
31
31
  # @return [Hash]
32
32
  def delete(params)
@@ -36,7 +36,7 @@ module SevenApi::Resources
36
36
  end
37
37
 
38
38
  # Retrieve all subaccounts
39
- # read more: https://www.seven.io/en/docs/gateway/http-api/subaccounts/#read-subaccounts
39
+ # read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#list-subaccounts
40
40
  # @param params [Hash]
41
41
  # @return [Hash]
42
42
  def read(params = {})
@@ -44,7 +44,7 @@ module SevenApi::Resources
44
44
  end
45
45
 
46
46
  # Transfer credits to a subaccount
47
- # read more: https://www.seven.io/en/docs/gateway/http-api/subaccounts/#transfer-credit
47
+ # read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#manual-credit-transfer
48
48
  # @param params [Hash]
49
49
  # @return [Hash]
50
50
  def transfer_credits(params)
@@ -54,7 +54,7 @@ module SevenApi::Resources
54
54
  end
55
55
 
56
56
  # Update automatic charging of a subaccount
57
- # read more: https://www.seven.io/en/docs/gateway/http-api/subaccounts/#update-automatic-charging-of-the-subaccount
57
+ # read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#automatic-credit-transfer
58
58
  # @param params [Hash]
59
59
  # @return [Hash]
60
60
  def update(params)
@@ -11,7 +11,7 @@ module SevenApi::Resources
11
11
  }
12
12
 
13
13
  # Validate a phone number for using it as caller ID via our voice API
14
- # read more: https://www.seven.io/en/docs/gateway/http-api/caller-ids/
14
+ # read more: https://docs.seven.io/en/rest-api/endpoints/sender-identifiers#validate-sender-for-voice
15
15
  # @param params [Hash]
16
16
  # @return [Hash]
17
17
  def retrieve(params)
@@ -11,7 +11,7 @@ module SevenApi::Resources
11
11
  }
12
12
 
13
13
  # Convert text to speech, call number and read voice message out loud.
14
- # read more: https://www.seven.io/en/docs/gateway/http-api/voice/
14
+ # read more: https://docs.seven.io/en/rest-api/endpoints/voice#send-voice-call
15
15
  # @param params [Hash]
16
16
  # @return [String,Hash]
17
17
  def send(params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SevenApi
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
data/seven_api.gemspec CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'seven_api/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.add_development_dependency 'bundler', '~> 2.1'
8
- spec.add_development_dependency 'rake', '~> 13.0'
9
- spec.add_development_dependency 'rspec', '~> 3.9'
10
- spec.add_runtime_dependency 'faraday', '~> 1.1'
7
+ spec.add_development_dependency 'bundler', '~> 2.4'
8
+ spec.add_development_dependency 'rake', '~> 13.1'
9
+ spec.add_development_dependency 'rspec', '~> 3.13'
10
+ spec.add_runtime_dependency 'faraday', '~> 2.9'
11
11
  spec.author = 'seven communications GmbH & Co. KG'
12
12
  spec.description = 'Send SMS & text-to-speech messages via the seven SMS Gateway.'
13
13
  spec.email = 'support@seven.io'
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/seven-io/ruby-client'
16
16
  spec.license = 'MIT'
17
17
  spec.name = 'seven_api'
18
- spec.required_ruby_version = '>= 2.6.0'
18
+ spec.required_ruby_version = '>= 3.1.0'
19
19
  spec.summary = 'Official API Client for the seven SMS Gateway'
20
20
  spec.test_files = Dir['spec/**/*']
21
21
  spec.version = SevenApi::VERSION
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'seven_api/resources/analytics'
5
+
6
+ RSpec.describe SevenApi, 'analytics' do
7
+ base_stub = {
8
+ hlr: 0,
9
+ inbound: 72,
10
+ mnp: 0,
11
+ rcs: 1,
12
+ sms: 145,
13
+ usage_eur: 0.208,
14
+ voice: 0
15
+ }
16
+ helper = Helper.new(SevenApi::Resources::Analytics)
17
+
18
+ it 'returns an array with analytics grouped by country' do
19
+ stub = [base_stub.merge({ country: "DE" })]
20
+ params = { country: "DE" }
21
+ fn = helper.resource.method(:by_country)
22
+ path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_country]
23
+ entries = helper.request(fn, stub, params, path)
24
+ expect(entries).to be_a(Array)
25
+ end
26
+
27
+ it 'returns an array with analytics grouped by date' do
28
+ stub = [base_stub.merge({ date: "2020-05-13" })]
29
+ fn = helper.resource.method(:by_date)
30
+ path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_date]
31
+ entries = helper.request(fn, stub, nil, path)
32
+ expect(entries).to be_a(Array)
33
+ end
34
+
35
+ it 'returns an array with analytics grouped by label' do
36
+ stub = [base_stub.merge({ label: "Label" })]
37
+ fn = helper.resource.method(:by_label)
38
+ path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_label]
39
+ entries = helper.request(fn, stub, nil, path)
40
+ expect(entries).to be_a(Array)
41
+ end
42
+
43
+ it 'returns an array with analytics grouped by subaccount' do
44
+ stub = [base_stub.merge({ account: "Subaccount" })]
45
+ path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_subaccount]
46
+ entries = helper.request(helper.resource.method(:by_subaccount), stub, nil, path)
47
+ expect(entries).to be_a(Array)
48
+ end
49
+ end
@@ -6,7 +6,13 @@ require 'seven_api/resources/balance'
6
6
  RSpec.describe SevenApi, 'balance' do
7
7
  it 'returns the account balance' do
8
8
  helper = Helper.new(SevenApi::Resources::Balance)
9
- balance = helper.request(helper.resource.method(:retrieve), 155.55)
10
- expect(balance).to be_a(Float)
9
+ stub = {
10
+ amount: 44.631,
11
+ currency: "EUR"
12
+ }
13
+ balance = helper.request(helper.resource.method(:retrieve), stub)
14
+ expect(balance).to be_a(Hash)
15
+ expect(balance[:amount]).to be_a(Float)
16
+ expect(balance[:currency]).to be_a(String)
11
17
  end
12
18
  end
@@ -4,76 +4,70 @@ require 'spec_helper'
4
4
  require 'seven_api/contacts'
5
5
  require 'seven_api/resources/contacts'
6
6
 
7
+ dummy_contact = {
8
+ "id": 12876882,
9
+ "avatar": "https://static.seven.io/uploads/contact_images/4A000c0d4e9431F483090dE8D13F3806.jpg",
10
+ "validation": {
11
+ "state": nil,
12
+ "timestamp": nil
13
+ },
14
+ "initials": {
15
+ "initials": "",
16
+ "color": "EEE0C9"
17
+ },
18
+ "properties": {
19
+ "address": nil,
20
+ "birthday": nil,
21
+ "city": nil,
22
+ "email": nil,
23
+ "firstname": nil,
24
+ "home_number": nil,
25
+ "lastname": nil,
26
+ "mobile_number": nil,
27
+ "notes": nil,
28
+ "postal_code": nil,
29
+ },
30
+ "groups": [
31
+ ],
32
+ "created": "2024-01-09 13:12:48"
33
+ }
34
+
7
35
  RSpec.describe SevenApi, 'contacts' do
8
- $new_contact_id = nil
36
+ $new_number_id = nil
9
37
 
10
38
  def assert_new(response_body)
11
39
  if response_body.is_a?(String)
12
- code, $new_contact_id = response_body.split("\n")
13
- $new_contact_id = $new_contact_id.to_i
40
+ code, $new_number_id = response_body.split("\n")
41
+ $new_number_id = $new_number_id.to_i
14
42
  else
15
43
  code = response_body[:return]
16
- $new_contact_id = response_body[:id]
44
+ $new_number_id = response_body[:id]
17
45
  end
18
46
 
19
47
  expect(code).to be_numeric
20
- expect($new_contact_id).to be_an_instance_of(Integer)
48
+ expect($new_number_id).to be_an_instance_of(Integer)
21
49
  end
22
50
 
23
51
  def assert_contact(contact)
24
- if contact.is_a?(String)
25
- id, name, number = contact.split(';')
26
-
27
- id = id.gsub('"', '')
28
- name = name.gsub('"', '')
29
- number = number.gsub('"', '')
30
- else
31
- id = contact[:ID]
32
- name = contact[:Name]
33
- number = contact[:Number]
34
- end
35
-
36
- expect(id).to be_numeric
37
- expect(name).to be_an_instance_of(String)
38
- expect(number.sub('+', '')).to be_numeric
39
- end
40
-
41
- it 'returns all contacts as CSV' do
42
- stub = <<~CSV
43
- "4848436";"";""
44
- "4848437";"";""
45
- "4848433";"Alf Albert";"007"
46
- "3172517";"BNN Nolte";"004911112"
47
- "4848434";"Harry Harald";"0049123456"
48
- "4848431";"Karl Konrad";"00123456"
49
- "4848432";"Petra Pan";"00513414"
50
- "2925186";"Tom Tester";"004901234567890"
51
- CSV
52
-
53
- helper = Helper.new(SevenApi::Resources::Contacts)
54
- body = helper.request(helper.resource.method(:read), stub)
55
-
56
- expect(body).to be_a(String)
57
-
58
- body.split("\n").each do |contact|
59
- assert_contact(contact)
60
- end
52
+ expect(contact[:id]).to be_numeric
61
53
  end
62
54
 
63
- it 'returns all contacts as JSON' do
64
- stub = [
65
- { ID: '4848436', Name: '', Number: '' },
66
- { ID: '4848437', Name: '', Number: '' },
67
- { ID: '4848433', Name: 'Alf Albert', Number: '007' },
68
- { ID: '3172517', Name: 'BNN Nolte', Number: '004911112' },
69
- { ID: '4848434', Name: 'Harry Harald', Number: '0049123456' },
70
- { ID: '4848431', Name: 'Karl Konrad', Number: '00123456' },
71
- { ID: '4848432', Name: 'Petra Pan', Number: '00513414' },
72
- { ID: '2925186', Name: 'Tom Tester', Number: '004901234567890' }
73
- ]
55
+ it 'returns all contacts' do
56
+ stub = {
57
+ data: [
58
+ dummy_contact,
59
+ dummy_contact
60
+ ],
61
+ pagingMetadata: {
62
+ count: 30,
63
+ has_more: true,
64
+ offset: 0,
65
+ total: 20013
66
+ },
67
+ }
74
68
 
75
69
  helper = Helper.new(SevenApi::Resources::Contacts)
76
- body = helper.request(helper.resource.method(:read), stub, { json: true })
70
+ body = helper.request(helper.resource.method(:all), stub)
77
71
 
78
72
  expect(body).to be_a(Array)
79
73
 
@@ -82,28 +76,10 @@ RSpec.describe SevenApi, 'contacts' do
82
76
  end
83
77
  end
84
78
 
85
- it 'creates a contact and returns its ID as TEXT' do
86
- stub = <<~TEXT
87
- 152
88
- 4868400
89
- TEXT
90
-
91
- helper = Helper.new(SevenApi::Resources::Contacts)
92
- body = helper.request(helper.resource.method(:write), stub, {})
93
-
94
- expect(body).to be_a(String)
95
-
96
- assert_new(body)
97
- end
98
-
99
- it 'deletes a contact with given ID and return code' do
100
- helper = Helper.new(SevenApi::Resources::Contacts)
101
- expect(helper.request(helper.resource.method(:delete), 152, { id: $new_contact_id })).to be_a(Integer)
102
- end
103
-
104
79
  it 'creates a contact and returns its ID as JSON' do
80
+ stub = dummy_contact
105
81
  helper = Helper.new(SevenApi::Resources::Contacts)
106
- body = helper.request(helper.resource.method(:write), { id: 4868401, return: '152' }, { json: true })
82
+ body = helper.request(helper.resource.method(:create), stub)
107
83
 
108
84
  expect(body).to be_a(Hash)
109
85
 
@@ -114,13 +90,8 @@ RSpec.describe SevenApi, 'contacts' do
114
90
  helper = Helper.new(SevenApi::Resources::Contacts)
115
91
  body = helper.request(
116
92
  helper.resource.method(:delete),
117
- {
118
- return: '152'
119
- },
120
- {
121
- id: $new_contact_id,
122
- json: true,
123
- }
93
+ nil,
94
+ 0
124
95
  )
125
96
 
126
97
  expect(body).to be_a(Hash)
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'seven_api/resources/groups'
5
+
6
+ dummy_group = {
7
+ "created": "2023-12-21 21:59:53",
8
+ "id": 17923,
9
+ "members_count": 543,
10
+ "name": "Group 1",
11
+ }
12
+
13
+ RSpec.describe SevenApi, 'groups' do
14
+ $new_number_id = nil
15
+
16
+ def assert_new(response_body)
17
+ code = response_body[:return]
18
+ $new_number_id = response_body[:id]
19
+
20
+ expect(code).to be_numeric
21
+ expect($new_number_id).to be_an_instance_of(Integer)
22
+ end
23
+
24
+ def assert_group(group)
25
+ expect(group[:id]).to be_numeric
26
+ expect(group[:name]).to be_an_instance_of(String)
27
+ end
28
+
29
+ it 'returns all groups' do
30
+ stub = {
31
+ data: [
32
+ dummy_group,
33
+ dummy_group
34
+ ],
35
+ pagingMetadata: {
36
+ count: 30,
37
+ has_more: true,
38
+ offset: 0,
39
+ total: 20013
40
+ },
41
+ }
42
+
43
+ helper = Helper.new(SevenApi::Resources::Groups)
44
+ body = helper.request(helper.resource.method(:all), stub)
45
+
46
+ expect(body).to be_a(Array)
47
+
48
+ body.each do |group|
49
+ assert_group(group)
50
+ end
51
+ end
52
+
53
+ it 'creates a group and returns its ID' do
54
+ stub = dummy_group
55
+ helper = Helper.new(SevenApi::Resources::Groups)
56
+ body = helper.request(helper.resource.method(:create), stub)
57
+
58
+ expect(body).to be_a(Hash)
59
+
60
+ assert_new(body)
61
+ end
62
+
63
+ it 'deletes a group with given ID' do
64
+ helper = Helper.new(SevenApi::Resources::Groups)
65
+ body = helper.request(
66
+ helper.resource.method(:delete),
67
+ nil,
68
+ 0
69
+ )
70
+
71
+ expect(body).to be_a(Hash)
72
+ expect(body[:return]).to be_a(String)
73
+ end
74
+ end