seven_api 0.5.0 → 0.6.1

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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -6
  3. data/.idea/inspectionProfiles/Project_Default.xml +5 -5
  4. data/.idea/ruby-client.iml +51 -4
  5. data/Gemfile +2 -2
  6. data/LICENSE +21 -21
  7. data/README.md +3 -3
  8. data/Rakefile +5 -5
  9. data/doc/{Sms77 → SevenApi}/Client.html +229 -229
  10. data/doc/{Sms77 → SevenApi}/Contacts/Action.html +130 -130
  11. data/doc/{Sms77 → SevenApi}/Contacts.html +125 -125
  12. data/doc/{Sms77 → SevenApi}/Endpoint.html +186 -186
  13. data/doc/{Sms77 → SevenApi}/Hooks/Action.html +130 -130
  14. data/doc/{Sms77 → SevenApi}/Hooks/EventType.html +145 -145
  15. data/doc/{Sms77 → SevenApi}/Hooks/RequestMethod.html +130 -130
  16. data/doc/{Sms77 → SevenApi}/Hooks/Validator.html +597 -597
  17. data/doc/{Sms77 → SevenApi}/Hooks.html +125 -125
  18. data/doc/{Sms77 → SevenApi}/Journal/Type.html +135 -135
  19. data/doc/{Sms77 → SevenApi}/Journal/Validator.html +393 -393
  20. data/doc/{Sms77 → SevenApi}/Journal.html +125 -125
  21. data/doc/{Sms77 → SevenApi}/Lookup/Type.html +135 -135
  22. data/doc/{Sms77 → SevenApi}/Lookup.html +125 -125
  23. data/doc/{Sms77 → SevenApi}/Resource.html +869 -869
  24. data/doc/{Sms77 → SevenApi}/Resources/Analytics.html +262 -262
  25. data/doc/{Sms77 → SevenApi}/Resources/Balance.html +245 -245
  26. data/doc/{Sms77 → SevenApi}/Resources/Contacts.html +448 -448
  27. data/doc/{Sms77 → SevenApi}/Resources/Hooks.html +456 -456
  28. data/doc/{Sms77 → SevenApi}/Resources/Journal.html +260 -260
  29. data/doc/{Sms77 → SevenApi}/Resources/Lookup.html +539 -539
  30. data/doc/{Sms77 → SevenApi}/Resources/Pricing.html +262 -262
  31. data/doc/{Sms77 → SevenApi}/Resources/Sms.html +260 -260
  32. data/doc/{Sms77 → SevenApi}/Resources/Status.html +260 -260
  33. data/doc/{Sms77 → SevenApi}/Resources/Subaccounts.html +650 -650
  34. data/doc/{Sms77 → SevenApi}/Resources/ValidateForVoice.html +260 -260
  35. data/doc/{Sms77 → SevenApi}/Resources/Voice.html +260 -260
  36. data/doc/SevenApi/Resources.html +128 -0
  37. data/doc/{Sms77 → SevenApi}/Sms/Type.html +125 -125
  38. data/doc/{Sms77 → SevenApi}/Sms.html +125 -125
  39. data/doc/{Sms77 → SevenApi}/Subaccounts/Action.html +140 -140
  40. data/doc/SevenApi/Subaccounts/Validator.html +490 -0
  41. data/doc/{Sms77 → SevenApi}/Subaccounts.html +125 -125
  42. data/doc/{Sms77 → SevenApi}/Util.html +1032 -1032
  43. data/doc/{Sms77.html → SevenApi.html} +145 -145
  44. data/doc/_index.html +443 -443
  45. data/doc/class_list.html +51 -51
  46. data/doc/css/full_list.css +58 -58
  47. data/doc/css/style.css +497 -497
  48. data/doc/file.README.html +110 -111
  49. data/doc/file_list.html +56 -56
  50. data/doc/frames.html +17 -17
  51. data/doc/index.html +110 -111
  52. data/doc/js/app.js +314 -314
  53. data/doc/js/full_list.js +216 -216
  54. data/doc/js/jquery.js +3 -3
  55. data/doc/method_list.html +563 -563
  56. data/doc/top-level-namespace.html +109 -109
  57. data/document.sh +3 -0
  58. data/lib/seven_api/client.rb +32 -30
  59. data/lib/seven_api/contacts.rb +5 -10
  60. data/lib/seven_api/endpoint.rb +5 -0
  61. data/lib/seven_api/hooks.rb +69 -67
  62. data/lib/seven_api/journal.rb +39 -39
  63. data/lib/seven_api/lookup.rb +12 -11
  64. data/lib/seven_api/numbers.rb +9 -0
  65. data/lib/seven_api/paginated.rb +10 -0
  66. data/lib/seven_api/rcs.rb +9 -0
  67. data/lib/seven_api/resource.rb +8 -4
  68. data/lib/seven_api/resources/analytics.rb +54 -21
  69. data/lib/seven_api/resources/balance.rb +19 -19
  70. data/lib/seven_api/resources/contacts.rb +56 -38
  71. data/lib/seven_api/resources/groups.rb +57 -0
  72. data/lib/seven_api/resources/hooks.rb +40 -40
  73. data/lib/seven_api/resources/journal.rb +20 -20
  74. data/lib/seven_api/resources/lookup.rb +63 -47
  75. data/lib/seven_api/resources/numbers.rb +71 -0
  76. data/lib/seven_api/resources/pricing.rb +20 -20
  77. data/lib/seven_api/resources/rcs.rb +39 -0
  78. data/lib/seven_api/resources/sms.rb +29 -20
  79. data/lib/seven_api/resources/status.rb +20 -20
  80. data/lib/seven_api/resources/subaccounts.rb +65 -65
  81. data/lib/seven_api/resources/validate_for_voice.rb +20 -20
  82. data/lib/seven_api/resources/voice.rb +29 -20
  83. data/lib/seven_api/sms.rb +9 -9
  84. data/lib/seven_api/subaccounts.rb +55 -55
  85. data/lib/seven_api/util.rb +68 -68
  86. data/lib/seven_api/version.rb +5 -5
  87. data/lib/seven_api.rb +6 -6
  88. data/release.sh +4 -4
  89. data/seven_api.gemspec +5 -5
  90. data/spec/EnvKeyStore.rb +14 -14
  91. data/spec/matchers.rb +22 -22
  92. data/spec/seven_api/analytics_spec.rb +49 -0
  93. data/spec/seven_api/balance_spec.rb +18 -12
  94. data/spec/seven_api/client_spec.rb +15 -15
  95. data/spec/seven_api/contacts_spec.rb +100 -129
  96. data/spec/seven_api/groups_spec.rb +74 -0
  97. data/spec/seven_api/hooks_spec.rb +108 -108
  98. data/spec/seven_api/instance_spec.rb +22 -22
  99. data/spec/seven_api/journal_spec.rb +86 -86
  100. data/spec/seven_api/lookup_spec.rb +197 -179
  101. data/spec/seven_api/numbers_spec.rb +135 -0
  102. data/spec/seven_api/pricing_spec.rb +76 -76
  103. data/spec/seven_api/rcs_spec.rb +99 -0
  104. data/spec/seven_api/sms_spec.rb +103 -103
  105. data/spec/seven_api/subaccounts_spec.rb +121 -121
  106. data/spec/seven_api/validate_for_voice_spec.rb +19 -19
  107. data/spec/seven_api/voice_spec.rb +51 -51
  108. data/spec/seven_api_spec.rb +9 -9
  109. data/spec/spec_helper.rb +8 -17
  110. metadata +62 -50
  111. data/doc/Sms77/Resources.html +0 -128
  112. data/doc/Sms77/Subaccounts/Validator.html +0 -490
data/spec/EnvKeyStore.rb CHANGED
@@ -1,15 +1,15 @@
1
- class EnvKeyStore
2
- def initialize(key)
3
- @key = "SEVEN_TEST_#{key}"
4
-
5
- @store = ENV[@key]
6
- end
7
-
8
- def get(fallback = nil)
9
- @store.nil? ? fallback : @store
10
- end
11
-
12
- def set(val, only_on_nil = false)
13
- @store = val unless only_on_nil
14
- end
1
+ class EnvKeyStore
2
+ def initialize(key)
3
+ @key = "SEVEN_TEST_#{key}"
4
+
5
+ @store = ENV[@key]
6
+ end
7
+
8
+ def get(fallback = nil)
9
+ @store.nil? ? fallback : @store
10
+ end
11
+
12
+ def set(val, only_on_nil = false)
13
+ @store = val unless only_on_nil
14
+ end
15
15
  end
data/spec/matchers.rb CHANGED
@@ -1,23 +1,23 @@
1
- RSpec::Matchers.define :be_nil_or_lengthy_string do
2
- match do |val|
3
- SevenApi::Util::nil_or_lengthy_string?(val)
4
- end
5
- end
6
-
7
- RSpec::Matchers.define :be_boolean do
8
- match do |val|
9
- SevenApi::Util::boolean?(val)
10
- end
11
- end
12
-
13
- RSpec::Matchers.define :be_numeric do
14
- match do |val|
15
- SevenApi::Util::numeric?(val)
16
- end
17
- end
18
-
19
- RSpec::Matchers.define :be_lengthy_string do
20
- match do |val|
21
- SevenApi::Util::lengthy_string?(val)
22
- end
1
+ RSpec::Matchers.define :be_nil_or_lengthy_string do
2
+ match do |val|
3
+ SevenApi::Util::nil_or_lengthy_string?(val)
4
+ end
5
+ end
6
+
7
+ RSpec::Matchers.define :be_boolean do
8
+ match do |val|
9
+ SevenApi::Util::boolean?(val)
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.define :be_numeric do
14
+ match do |val|
15
+ SevenApi::Util::numeric?(val)
16
+ end
17
+ end
18
+
19
+ RSpec::Matchers.define :be_lengthy_string do
20
+ match do |val|
21
+ SevenApi::Util::lengthy_string?(val)
22
+ end
23
23
  end
@@ -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
@@ -1,12 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'seven_api/resources/balance'
5
-
6
- RSpec.describe SevenApi, 'balance' do
7
- it 'returns the account balance' do
8
- helper = Helper.new(SevenApi::Resources::Balance)
9
- balance = helper.request(helper.resource.method(:retrieve), 155.55)
10
- expect(balance).to be_a(Float)
11
- end
12
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'seven_api/resources/balance'
5
+
6
+ RSpec.describe SevenApi, 'balance' do
7
+ it 'returns the account balance' do
8
+ helper = Helper.new(SevenApi::Resources::Balance)
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)
17
+ end
18
+ end
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'seven_api/client'
5
- require 'seven_api/resource'
6
-
7
- RSpec.describe SevenApi, 'client' do
8
- it 'should contain all resource modules' do
9
- client = SevenApi::Client.new(SevenApi::Resource.new('x'))
10
-
11
- client.instance_variables.each do |var|
12
- expect(SevenApi::Resources.const_get(client.instance_variable_get(var).class.name)).to be_truthy
13
- end
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'seven_api/client'
5
+ require 'seven_api/resource'
6
+
7
+ RSpec.describe SevenApi, 'client' do
8
+ it 'should contain all resource modules' do
9
+ client = SevenApi::Client.new(SevenApi::Resource.new('x'))
10
+
11
+ client.instance_variables.each do |var|
12
+ expect(SevenApi::Resources.const_get(client.instance_variable_get(var).class.name)).to be_truthy
13
+ end
14
+ end
15
+ end
@@ -1,129 +1,100 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'seven_api/contacts'
5
- require 'seven_api/resources/contacts'
6
-
7
- RSpec.describe SevenApi, 'contacts' do
8
- $new_contact_id = nil
9
-
10
- def assert_new(response_body)
11
- if response_body.is_a?(String)
12
- code, $new_contact_id = response_body.split("\n")
13
- $new_contact_id = $new_contact_id.to_i
14
- else
15
- code = response_body[:return]
16
- $new_contact_id = response_body[:id]
17
- end
18
-
19
- expect(code).to be_numeric
20
- expect($new_contact_id).to be_an_instance_of(Integer)
21
- end
22
-
23
- 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
61
- end
62
-
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
- ]
74
-
75
- helper = Helper.new(SevenApi::Resources::Contacts)
76
- body = helper.request(helper.resource.method(:read), stub, { json: true })
77
-
78
- expect(body).to be_a(Array)
79
-
80
- body.each do |contact|
81
- assert_contact(contact)
82
- end
83
- end
84
-
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
- it 'creates a contact and returns its ID as JSON' do
105
- helper = Helper.new(SevenApi::Resources::Contacts)
106
- body = helper.request(helper.resource.method(:write), { id: 4868401, return: '152' }, { json: true })
107
-
108
- expect(body).to be_a(Hash)
109
-
110
- assert_new(body)
111
- end
112
-
113
- it 'deletes a contact with given ID and return code as JSON' do
114
- helper = Helper.new(SevenApi::Resources::Contacts)
115
- body = helper.request(
116
- helper.resource.method(:delete),
117
- {
118
- return: '152'
119
- },
120
- {
121
- id: $new_contact_id,
122
- json: true,
123
- }
124
- )
125
-
126
- expect(body).to be_a(Hash)
127
- expect(body[:return]).to be_a(String)
128
- end
129
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'seven_api/contacts'
5
+ require 'seven_api/resources/contacts'
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
+
35
+ RSpec.describe SevenApi, 'contacts' do
36
+ $new_number_id = nil
37
+
38
+ def assert_new(response_body)
39
+ if response_body.is_a?(String)
40
+ code, $new_number_id = response_body.split("\n")
41
+ $new_number_id = $new_number_id.to_i
42
+ else
43
+ code = response_body[:return]
44
+ $new_number_id = response_body[:id]
45
+ end
46
+
47
+ expect(code).to be_numeric
48
+ expect($new_number_id).to be_an_instance_of(Integer)
49
+ end
50
+
51
+ def assert_contact(contact)
52
+ expect(contact[:id]).to be_numeric
53
+ end
54
+
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
+ }
68
+
69
+ helper = Helper.new(SevenApi::Resources::Contacts)
70
+ body = helper.request(helper.resource.method(:all), stub)
71
+
72
+ expect(body).to be_a(Array)
73
+
74
+ body.each do |contact|
75
+ assert_contact(contact)
76
+ end
77
+ end
78
+
79
+ it 'creates a contact and returns its ID as JSON' do
80
+ stub = dummy_contact
81
+ helper = Helper.new(SevenApi::Resources::Contacts)
82
+ body = helper.request(helper.resource.method(:create), stub)
83
+
84
+ expect(body).to be_a(Hash)
85
+
86
+ assert_new(body)
87
+ end
88
+
89
+ it 'deletes a contact with given ID and return code as JSON' do
90
+ helper = Helper.new(SevenApi::Resources::Contacts)
91
+ body = helper.request(
92
+ helper.resource.method(:delete),
93
+ nil,
94
+ 0
95
+ )
96
+
97
+ expect(body).to be_a(Hash)
98
+ expect(body[:return]).to be_a(String)
99
+ end
100
+ end
@@ -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