ince-api 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 296b84cce1213106b1291e9db2313cc7002ef5c6b67a01d3b664e6933384a4c3
4
- data.tar.gz: 3e1334fafc82cbfbedfcf8e584e6328124051d6a525584626b64f0113f2bf50f
3
+ metadata.gz: 3b2591474c566e9979fb552d5263c599284f5e00641d981fe5ca5b66f3b4edd0
4
+ data.tar.gz: 9cf7dab00dc5a9d2089d5412e67d723d7ffb6ff4defe6ace47de7d6d3144dc3e
5
5
  SHA512:
6
- metadata.gz: fd2b4e8cf09960cf08f6b01b02fe4aeb928d1d7472ca23f78f8d99fee8d10e3e91b429f7dcc7f617ef1f9941d76e8e194120512a8583a6f79790f86657f6e8b2
7
- data.tar.gz: 55afc4f0f0866d4b999823f0a57d80e06f43847fde6c86d02b9c37c9c95a8f63274c5394e7b3aeeca62a27650ec71ade32ce8762bcd6f917d4e801167e6e44c0
6
+ metadata.gz: a030a05bc090b623953cff50e3c8b94a81de188da327ad62f13303a92d0ed49b1e7b65522238ecacd1e6b9aa58c99b4e3469743438618bf7d35126081093fb42
7
+ data.tar.gz: 36dc8d5cd6445d4af246e4f05f98e20c6ff9e1a8c0060cbd8a359aeb3bd29e655d9861101f5003f5af15403dee014be740f07a6b24a9b88f009d0bcf9cd7dc4c
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ince-api (0.2.0)
4
+ ince-api (0.3.1)
5
5
  base64 (~> 0.1)
6
6
  net-http (~> 0.2)
7
7
  openssl
@@ -10,44 +10,51 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.8.0)
14
- public_suffix (>= 2.0.2, < 5.0)
15
- base64 (0.2.0)
13
+ addressable (2.8.9)
14
+ public_suffix (>= 2.0.2, < 8.0)
15
+ base64 (0.3.0)
16
+ bigdecimal (4.0.1)
16
17
  coderay (1.1.3)
17
- crack (0.4.5)
18
+ crack (1.0.1)
19
+ bigdecimal
18
20
  rexml
19
- diff-lcs (1.4.4)
20
- hashdiff (1.0.1)
21
- method_source (1.0.0)
22
- net-http (0.4.1)
23
- uri
24
- openssl (3.2.0)
25
- pry (0.14.1)
21
+ diff-lcs (1.6.2)
22
+ hashdiff (1.2.1)
23
+ io-console (0.8.2)
24
+ method_source (1.1.0)
25
+ net-http (0.9.1)
26
+ uri (>= 0.11.1)
27
+ openssl (4.0.1)
28
+ pry (0.16.0)
26
29
  coderay (~> 1.1)
27
30
  method_source (~> 1.0)
28
- public_suffix (4.0.6)
29
- rexml (3.2.5)
30
- rspec (3.10.0)
31
- rspec-core (~> 3.10.0)
32
- rspec-expectations (~> 3.10.0)
33
- rspec-mocks (~> 3.10.0)
34
- rspec-core (3.10.1)
35
- rspec-support (~> 3.10.0)
36
- rspec-expectations (3.10.1)
31
+ reline (>= 0.6.0)
32
+ public_suffix (7.0.5)
33
+ reline (0.6.3)
34
+ io-console (~> 0.5)
35
+ rexml (3.4.4)
36
+ rspec (3.13.2)
37
+ rspec-core (~> 3.13.0)
38
+ rspec-expectations (~> 3.13.0)
39
+ rspec-mocks (~> 3.13.0)
40
+ rspec-core (3.13.6)
41
+ rspec-support (~> 3.13.0)
42
+ rspec-expectations (3.13.5)
37
43
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.10.0)
39
- rspec-mocks (3.10.2)
44
+ rspec-support (~> 3.13.0)
45
+ rspec-mocks (3.13.8)
40
46
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.10.0)
42
- rspec-support (3.10.3)
43
- uri (0.13.0)
44
- vcr (6.0.0)
45
- webmock (3.14.0)
47
+ rspec-support (~> 3.13.0)
48
+ rspec-support (3.13.7)
49
+ uri (0.13.3)
50
+ vcr (6.4.0)
51
+ webmock (3.26.1)
46
52
  addressable (>= 2.8.0)
47
53
  crack (>= 0.3.2)
48
54
  hashdiff (>= 0.4.0, < 2.0.0)
49
55
 
50
56
  PLATFORMS
57
+ arm64-darwin-25
51
58
  ruby
52
59
 
53
60
  DEPENDENCIES
@@ -57,5 +64,31 @@ DEPENDENCIES
57
64
  vcr (~> 6.0)
58
65
  webmock (~> 3.14)
59
66
 
67
+ CHECKSUMS
68
+ addressable (2.8.9) sha256=cc154fcbe689711808a43601dee7b980238ce54368d23e127421753e46895485
69
+ base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
70
+ bigdecimal (4.0.1) sha256=8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7
71
+ coderay (1.1.3) sha256=dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b
72
+ crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
73
+ diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
74
+ hashdiff (1.2.1) sha256=9c079dbc513dfc8833ab59c0c2d8f230fa28499cc5efb4b8dd276cf931457cd1
75
+ ince-api (0.3.1)
76
+ io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
77
+ method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
78
+ net-http (0.9.1) sha256=25ba0b67c63e89df626ed8fac771d0ad24ad151a858af2cc8e6a716ca4336996
79
+ openssl (4.0.1) sha256=e27974136b7b02894a1bce46c5397ee889afafe704a839446b54dc81cb9c5f7d
80
+ pry (0.16.0) sha256=d76c69065698ed1f85e717bd33d7942c38a50868f6b0673c636192b3d1b6054e
81
+ public_suffix (7.0.5) sha256=1a8bb08f1bbea19228d3bed6e5ed908d1cb4f7c2726d18bd9cadf60bc676f623
82
+ reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
83
+ rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142
84
+ rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
85
+ rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
86
+ rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
87
+ rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
88
+ rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
89
+ uri (0.13.3) sha256=ed4565c15b73602437a45d6dccb326fefcad0cc8c83794473af0b0439b2e1ea7
90
+ vcr (6.4.0) sha256=077ac92cc16efc5904eb90492a18153b5e6ca5398046d8a249a7c96a9ea24ae6
91
+ webmock (3.26.1) sha256=4f696fb57c90a827c20aadb2d4f9058bbff10f7f043bd0d4c3f58791143b1cd7
92
+
60
93
  BUNDLED WITH
61
- 2.1.4
94
+ 4.0.7
data/ince-api.gemspec CHANGED
@@ -1,24 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'ince-api'
3
- s.version = '0.3.0'
4
- s.summary = "1nce API wrapper"
5
- s.description = "A simple wrapper for 1nce API"
6
- s.authors = ["Stanislaw Zawadzki"]
5
+ s.version = '0.3.1'
6
+ s.summary = '1nce API wrapper'
7
+ s.description = 'A simple wrapper for 1nce API'
8
+ s.authors = ['Stanislaw Zawadzki']
7
9
  s.email = 'st.zawadzki@gmail.com'
8
10
  s.homepage = 'https://rubygems.org/gems/ince-api'
9
- s.license = 'MIT'
11
+ s.license = 'MIT'
10
12
 
11
13
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
12
14
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
15
  s.require_paths = ['lib']
14
16
  s.license = 'MIT'
15
- s.add_dependency 'uri', '~> 0.13'
17
+ s.add_dependency 'base64', '~> 0.1'
16
18
  s.add_dependency 'net-http', '~> 0.2'
17
19
  s.add_dependency 'openssl'
18
- s.add_dependency 'base64', '~> 0.1'
20
+ s.add_dependency 'uri', '~> 0.13'
19
21
  s.add_development_dependency 'pry', '~> 0.13'
20
22
  s.add_development_dependency 'rspec', '~> 3.9'
21
- s.add_development_dependency 'webmock', '~> 3.14'
22
23
  s.add_development_dependency 'vcr', '~> 6.0'
24
+ s.add_development_dependency 'webmock', '~> 3.14'
23
25
  end
24
-
data/lib/ince-api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'net/http'
3
5
  require 'openssl'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module InceApi
@@ -7,19 +9,21 @@ module InceApi
7
9
  @password = password
8
10
  end
9
11
 
10
- URL = URI("https://api.1nce.com/management-api/oauth/token")
12
+ URL = URI('https://api.1nce.com/management-api/oauth/token')
11
13
 
12
14
  def create_token
13
15
  response = connection.request(request)
14
16
  JSON.parse(response.body)
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  def request
18
22
  Net::HTTP::Post.new(URL).tap do |request|
19
- request["Accept"] = 'application/json'
20
- request["Content-Type"] = 'application/x-www-form-urlencoded'
21
- request["Authorization"] = "Basic #{encoded_credentials}"
22
- request.body = "grant_type=client_credentials"
23
+ request['Accept'] = 'application/json'
24
+ request['Content-Type'] = 'application/x-www-form-urlencoded'
25
+ request['Authorization'] = "Basic #{encoded_credentials}"
26
+ request.body = 'grant_type=client_credentials'
23
27
  end
24
28
  end
25
29
 
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class CreateSms
3
- def initialize(access_token:, iccid:, params:{})
5
+ def initialize(access_token:, iccid:, params: {})
4
6
  @access_token = access_token
5
7
  @iccid = iccid
6
8
  @params = params
@@ -8,12 +10,17 @@ module InceApi
8
10
 
9
11
  def send
10
12
  response = connection.request(request)
11
- response.code.to_i == 201 ? allowed_params.merge(status: 'OK') : { status: 'FAILED', error_code: response.code.to_i}
13
+ if response.code.to_i == 201
14
+ allowed_params.merge(status: 'OK')
15
+ else
16
+ { status: 'FAILED',
17
+ error_code: response.code.to_i }
18
+ end
12
19
  end
13
20
 
14
21
  private
15
22
 
16
- ALLOWED_KEYS = %i(source_address payload udh dcs source_address_type expiry_date)
23
+ ALLOWED_KEYS = %i[source_address payload udh dcs source_address_type expiry_date].freeze
17
24
  def allowed_params
18
25
  @params.slice(*ALLOWED_KEYS)
19
26
  end
@@ -31,8 +38,8 @@ module InceApi
31
38
  def request
32
39
  Net::HTTP::Post.new(url).tap do |request|
33
40
  request.body = allowed_params.to_json
34
- request["Accept"] = 'application/json'
35
- request["Content-Type"] = 'application/json;charset=UTF-8'
41
+ request['Accept'] = 'application/json'
42
+ request['Content-Type'] = 'application/json;charset=UTF-8'
36
43
  request['Authorization'] = "Bearer #{@access_token}"
37
44
  end
38
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSim
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def sim
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Get.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSimConnectivity
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def sim
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Get.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSimDataQuota
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def sim_status
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Get.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSimSmsQuota
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def sim_status
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Get.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSimStatus
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def sim_status
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Get.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSimUsage
3
5
  def initialize(access_token:, iccid:, params: {})
@@ -8,16 +10,18 @@ module InceApi
8
10
 
9
11
  def sim_usage
10
12
  response = connection.request(request)
11
- if response.body != ''
12
- JSON.parse(response.body)
13
+ if response.body.to_s.empty?
14
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
13
15
  else
14
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
16
+ JSON.parse(response.body)
15
17
  end
18
+ rescue JSON::ParserError
19
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
16
20
  end
17
21
 
18
22
  private
19
23
 
20
- ALLOWED_KEYS = %i(start_dt end_dt)
24
+ ALLOWED_KEYS = %i[start_dt end_dt].freeze
21
25
  def params_query
22
26
  URI.encode_www_form @params.slice(*ALLOWED_KEYS)
23
27
  end
@@ -34,7 +38,7 @@ module InceApi
34
38
 
35
39
  def request
36
40
  Net::HTTP::Get.new(url).tap do |request|
37
- request["Accept"] = 'application/json'
41
+ request['Accept'] = 'application/json'
38
42
  request['Authorization'] = "Bearer #{@access_token}"
39
43
  end
40
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class GetSims
3
5
  attr_reader :headers
@@ -12,11 +14,13 @@ module InceApi
12
14
  @headers = response.each_header.to_h
13
15
 
14
16
  JSON.parse(response.body)
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
18
22
 
19
- ALLOWED_KEYS = %i(page pageSize q sort)
23
+ ALLOWED_KEYS = %i[page pageSize q sort].freeze
20
24
  def params_query
21
25
  URI.encode_www_form @params.slice(*ALLOWED_KEYS)
22
26
  end
@@ -33,7 +37,7 @@ module InceApi
33
37
 
34
38
  def request
35
39
  Net::HTTP::Get.new(url).tap do |request|
36
- request["Accept"] = 'application/json'
40
+ request['Accept'] = 'application/json'
37
41
  request['Authorization'] = "Bearer #{@access_token}"
38
42
  end
39
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class MultipleSimsConfiguration
3
5
  def initialize(access_token:, changes_array: [])
@@ -7,19 +9,19 @@ module InceApi
7
9
 
8
10
  def update_many
9
11
  response = connection.request(request)
10
- response.code.to_i == 201 ? { status: 'OK' } : { status: 'FAILED', error_code: response.code.to_i}
12
+ response.code.to_i == 201 ? { status: 'OK' } : { status: 'FAILED', error_code: response.code.to_i }
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- ALLOWED_KEYS = %i(iccid label imei_lock status)
17
+ ALLOWED_KEYS = %i[iccid label imei_lock status].freeze
16
18
  def body
17
- @changes_array.select{|sim_params| !sim_params[:iccid].nil?}
18
- .map{|sim_params| sim_params.slice(*ALLOWED_KEYS)}.to_json
19
+ @changes_array.reject { |sim_params| sim_params[:iccid].nil? }
20
+ .map { |sim_params| sim_params.slice(*ALLOWED_KEYS) }.to_json
19
21
  end
20
22
 
21
23
  def url
22
- @url ||= URI("https://api.1nce.com/management-api/v1/sims")
24
+ @url ||= URI('https://api.1nce.com/management-api/v1/sims')
23
25
  end
24
26
 
25
27
  def connection
@@ -31,8 +33,8 @@ module InceApi
31
33
  def request
32
34
  Net::HTTP::Post.new(url).tap do |request|
33
35
  request.body = body
34
- request["Accept"] = 'application/json'
35
- request["Content-Type"] = 'application/json;charset=UTF-8'
36
+ request['Accept'] = 'application/json'
37
+ request['Content-Type'] = 'application/json;charset=UTF-8'
36
38
  request['Authorization'] = "Bearer #{@access_token}"
37
39
  end
38
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class ResetConnectivity
3
5
  def initialize(access_token:, iccid:)
@@ -7,11 +9,13 @@ module InceApi
7
9
 
8
10
  def reset
9
11
  response = connection.request(request)
10
- if response.body != ''
11
- JSON.parse(response.body)
12
+ if response.body.to_s.empty?
13
+ { 'status_code' => 404, 'error_message' => 'SIM with ICCID not found' }
12
14
  else
13
- {'status_code' => 404, 'error_message' => 'SIM with ICCID not found'}
15
+ JSON.parse(response.body)
14
16
  end
17
+ rescue JSON::ParserError
18
+ { 'status_code' => response.code.to_i, 'error_message' => "Invalid JSON response: #{response.body[0..200]}" }
15
19
  end
16
20
 
17
21
  private
@@ -28,7 +32,7 @@ module InceApi
28
32
 
29
33
  def request
30
34
  Net::HTTP::Post.new(url).tap do |request|
31
- request["Accept"] = 'application/json'
35
+ request['Accept'] = 'application/json'
32
36
  request['Authorization'] = "Bearer #{@access_token}"
33
37
  end
34
38
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InceApi
2
4
  class SingleSimConfiguration
3
- def initialize(access_token:, iccid:, params:{})
5
+ def initialize(access_token:, iccid:, params: {})
4
6
  @access_token = access_token
5
7
  @iccid = iccid
6
8
  @params = params
@@ -8,12 +10,17 @@ module InceApi
8
10
 
9
11
  def update
10
12
  response = connection.request(request)
11
- response.code.to_i == 200 ? allowed_params.merge(status: 'OK') : { status: 'FAILED', error_code: response.code.to_i}
13
+ if response.code.to_i == 200
14
+ allowed_params.merge(status: 'OK')
15
+ else
16
+ { status: 'FAILED',
17
+ error_code: response.code.to_i }
18
+ end
12
19
  end
13
20
 
14
21
  private
15
22
 
16
- ALLOWED_KEYS = %i(label imei_lock status)
23
+ ALLOWED_KEYS = %i[label imei_lock status].freeze
17
24
  def allowed_params
18
25
  @params.slice(*ALLOWED_KEYS)
19
26
  end
@@ -31,8 +38,8 @@ module InceApi
31
38
  def request
32
39
  Net::HTTP::Put.new(url).tap do |request|
33
40
  request.body = allowed_params.to_json
34
- request["Accept"] = 'application/json'
35
- request["Content-Type"] = 'application/json;charset=UTF-8'
41
+ request['Accept'] = 'application/json'
42
+ request['Content-Type'] = 'application/json;charset=UTF-8'
36
43
  request['Authorization'] = "Bearer #{@access_token}"
37
44
  end
38
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::CreateAccessToken do
@@ -29,4 +31,3 @@ RSpec.describe InceApi::CreateAccessToken do
29
31
  end
30
32
  end
31
33
  end
32
-
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::CreateSms do
4
6
  it 'sends SMS to sim card' do
5
7
  VCR.use_cassette('create_sms') do
6
- payload = "test SMS"
7
- response = described_class.new(access_token: @token, iccid: '8988228066602306770', params: {payload: payload }).send
8
+ payload = 'test SMS'
9
+ response = described_class.new(access_token: @token, iccid: '8988228066602306770',
10
+ params: { payload: payload }).send
8
11
  expect(response[:status]).to eq 'OK'
9
12
  expect(response[:payload]).to eq payload
10
13
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSimConnectivity do
4
6
  it 'get one sim card - idle' do
5
7
  VCR.use_cassette('get_sim_connectivity') do
6
- response = described_class.new(access_token: "VALID TOKEN", iccid: '123456789').sim
8
+ response = described_class.new(access_token: 'VALID TOKEN', iccid: '123456789').sim
7
9
  expect(response['subscriber_info']['state']).to eq 'assumed_idle'
8
10
  end
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSimDataQuota do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSimSmsQuota do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSim do
@@ -12,7 +14,7 @@ RSpec.describe InceApi::GetSim do
12
14
  it 'wrond iccid' do
13
15
  VCR.use_cassette('get_sim_wrong_iccid') do
14
16
  response = described_class.new(access_token: 'VALID TOKEN', iccid: '11111222233444').sim
15
- expect(response['error_message']).to eq "SIM with ICCID not found"
17
+ expect(response['error_message']).to eq 'SIM with ICCID not found'
16
18
  expect(response['status_code']).to eq 404
17
19
  end
18
20
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
4
+ require 'webmock/rspec'
2
5
 
3
6
  RSpec.describe InceApi::GetSimStatus do
4
7
  it 'get one sim card status' do
@@ -9,4 +12,23 @@ RSpec.describe InceApi::GetSimStatus do
9
12
  expect(response['location']['operator']['name']).to eq 'Plus'
10
13
  end
11
14
  end
15
+
16
+ it 'returns error hash when API returns HTML instead of JSON' do
17
+ html_body = '<!doctype html><html><body>Service Unavailable</body></html>'
18
+ stub_request(:get, 'https://api.1nce.com/management-api/v1/sims/123/status')
19
+ .to_return(status: 503, body: html_body, headers: { 'Content-Type' => 'text/html' })
20
+
21
+ response = described_class.new(access_token: 'token', iccid: '123').sim_status
22
+ expect(response['status_code']).to eq 503
23
+ expect(response['error_message']).to start_with('Invalid JSON response:')
24
+ end
25
+
26
+ it 'returns 404 error hash when body is empty' do
27
+ stub_request(:get, 'https://api.1nce.com/management-api/v1/sims/123/status')
28
+ .to_return(status: 200, body: '', headers: {})
29
+
30
+ response = described_class.new(access_token: 'token', iccid: '123').sim_status
31
+ expect(response['status_code']).to eq 404
32
+ expect(response['error_message']).to eq 'SIM with ICCID not found'
33
+ end
12
34
  end
@@ -1,18 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSimUsage do
4
6
  it 'get all sim cards' do
5
7
  VCR.use_cassette('get_sim_usage') do
6
8
  response = described_class.new(access_token: 'VALID TOKEN', iccid: '8988228066602306770').sim_usage
7
- expect(response["stats"].size).to eq 15
8
- expect(response['stats'].first['date']).to eq "2021-11-14"
9
+ expect(response['stats'].size).to eq 15
10
+ expect(response['stats'].first['date']).to eq '2021-11-14'
9
11
  expect(response['stats'].first['data']['volume']).to eq '0'
10
12
  end
11
13
  end
12
14
 
13
15
  xit 'get sim usage with params' do
14
16
  VCR.use_cassette('get_sims_usage_with_params') do
15
- response = described_class.new(access_token: @token, iccid: '8988228066602306770', params: {start_dt: 2021-11-10, end_dt: 2021-11-12}).sim_usage
17
+ described_class.new(access_token: @token, iccid: '8988228066602306770',
18
+ params: { start_dt: 2021 - 11 - 10, end_dt: 2021 - 11 - 12 }).sim_usage
16
19
  end
17
20
  end
18
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::GetSims do
@@ -11,19 +13,19 @@ RSpec.describe InceApi::GetSims do
11
13
 
12
14
  it 'get sim cards with params' do
13
15
  VCR.use_cassette('get_sims_with_params') do
14
- response = described_class.new(access_token: 'VALID TOKEN', params: {page: 2, pageSize: 5}).sims
16
+ response = described_class.new(access_token: 'VALID TOKEN', params: { page: 2, pageSize: 5 }).sims
15
17
  expect(response.size).to eq 5
16
18
  end
17
19
  end
18
20
 
19
21
  it 'paginates results' do
20
- VCR.use_cassette('get_sims_with_params_page_1') do
21
- @response_p1 = described_class.new(access_token: 'VALID TOKEN', params: {page: 1, pageSize: 5}).sims
22
+ VCR.use_cassette('get_sims_with_params_page_1') do
23
+ @response_p1 = described_class.new(access_token: 'VALID TOKEN', params: { page: 1, pageSize: 5 }).sims
22
24
  expect(@response_p1.size).to eq 5
23
25
  end
24
26
 
25
27
  VCR.use_cassette('get_sims_with_params') do
26
- @response_p2 = described_class.new(access_token: 'VALID TOKEN', params: {page: 2, pageSize: 5}).sims
28
+ @response_p2 = described_class.new(access_token: 'VALID TOKEN', params: { page: 2, pageSize: 5 }).sims
27
29
  expect(@response_p2.size).to eq 5
28
30
  end
29
31
 
@@ -32,7 +34,7 @@ RSpec.describe InceApi::GetSims do
32
34
 
33
35
  it 'returns headers too' do
34
36
  VCR.use_cassette('get_sims_with_params') do
35
- service = described_class.new(access_token: 'VALID TOKEN', params: {page: 2, pageSize: 5})
37
+ service = described_class.new(access_token: 'VALID TOKEN', params: { page: 2, pageSize: 5 })
36
38
  response = service.sims
37
39
  headers = service.headers
38
40
  expect(response.size).to eq 5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::MultipleSimsConfiguration do
@@ -10,7 +12,8 @@ RSpec.describe InceApi::MultipleSimsConfiguration do
10
12
 
11
13
  it 'updates one sim card - changes' do
12
14
  VCR.use_cassette('update_sims_label_change') do
13
- params = [{iccid: '8988228066602306711', label: 'Test Label 1'}, {iccid: '8988228066602307111', label: 'Test Label 2'}]
15
+ params = [{ iccid: '8988228066602306711', label: 'Test Label 1' },
16
+ { iccid: '8988228066602307111', label: 'Test Label 2' }]
14
17
  response = described_class.new(access_token: 'VALID TOKEN', changes_array: params).update_many
15
18
  expect(response[:status]).to eq 'OK'
16
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe InceApi::SingleSimConfiguration do
@@ -10,7 +12,8 @@ RSpec.describe InceApi::SingleSimConfiguration do
10
12
 
11
13
  it 'updates one sim card - changes' do
12
14
  VCR.use_cassette('update_sim_label_change') do
13
- response = described_class.new(access_token: 'VALID TOKEN', iccid: '8988228066602306770', params: {label: 'Test Label'}).update
15
+ response = described_class.new(access_token: 'VALID TOKEN', iccid: '8988228066602306770',
16
+ params: { label: 'Test Label' }).update
14
17
  expect(response[:status]).to eq 'OK'
15
18
  end
16
19
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ince-api'
2
4
  require 'vcr'
3
5
 
4
6
  VCR.configure do |config|
5
- config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
7
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
6
8
  config.hook_into :webmock
7
9
  end
8
10
 
@@ -17,4 +19,3 @@ RSpec.configure do |config|
17
19
 
18
20
  config.shared_context_metadata_behavior = :apply_to_host_groups
19
21
  end
20
-
metadata CHANGED
@@ -1,29 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ince-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislaw Zawadzki
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-07-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: uri
13
+ name: base64
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0.13'
18
+ version: '0.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0.13'
25
+ version: '0.1'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: net-http
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +52,19 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: base64
55
+ name: uri
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '0.1'
60
+ version: '0.13'
62
61
  type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '0.1'
67
+ version: '0.13'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: pry
71
70
  requirement: !ruby/object:Gem::Requirement
@@ -95,33 +94,33 @@ dependencies:
95
94
  - !ruby/object:Gem::Version
96
95
  version: '3.9'
97
96
  - !ruby/object:Gem::Dependency
98
- name: webmock
97
+ name: vcr
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: '3.14'
102
+ version: '6.0'
104
103
  type: :development
105
104
  prerelease: false
106
105
  version_requirements: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '3.14'
109
+ version: '6.0'
111
110
  - !ruby/object:Gem::Dependency
112
- name: vcr
111
+ name: webmock
113
112
  requirement: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - "~>"
116
115
  - !ruby/object:Gem::Version
117
- version: '6.0'
116
+ version: '3.14'
118
117
  type: :development
119
118
  prerelease: false
120
119
  version_requirements: !ruby/object:Gem::Requirement
121
120
  requirements:
122
121
  - - "~>"
123
122
  - !ruby/object:Gem::Version
124
- version: '6.0'
123
+ version: '3.14'
125
124
  description: A simple wrapper for 1nce API
126
125
  email: st.zawadzki@gmail.com
127
126
  executables: []
@@ -182,7 +181,6 @@ homepage: https://rubygems.org/gems/ince-api
182
181
  licenses:
183
182
  - MIT
184
183
  metadata: {}
185
- post_install_message:
186
184
  rdoc_options: []
187
185
  require_paths:
188
186
  - lib
@@ -197,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
195
  - !ruby/object:Gem::Version
198
196
  version: '0'
199
197
  requirements: []
200
- rubygems_version: 3.4.10
201
- signing_key:
198
+ rubygems_version: 3.6.9
202
199
  specification_version: 4
203
200
  summary: 1nce API wrapper
204
201
  test_files: