ince-api 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e17827a7e3e5724f8d6943ea91ac68c2248cd35563c6dd96208e23c5e828676
4
+ data.tar.gz: 687a059f3c92bafeaad731767b9210fdacad53c6987607425f3f2a26aec20fa2
5
+ SHA512:
6
+ metadata.gz: 9a4e2b50f07b1852b0fdf6c5a6bf0bd3dfe603ebf46923497f8844eb58ee3aa9be16bec7ea4f72f5d79283e4f31723c837f51d6d68279b37c8a2f5316dc19389
7
+ data.tar.gz: 2bf6f3da38ae721808c4e0656309a9d1aa1438142eb7c9f5f8de03eb69ea6572accbf6a0c0753c02aeb83f4f4e1780022a200bbc328761f093c861f92ba3d1f8
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # ince-api
2
+ Wrapper for 1nce API [API documentation](https://help.1nce.com/dev-hub/reference/api-welcome)
3
+
4
+ ## Instalation
5
+
6
+ The ince-api gem is available at rubygems.org. You can install with:
7
+
8
+ `gem install ince-api`
9
+
10
+ Alternatively, you can install the gem with bundler:
11
+
12
+ \# Gemfile
13
+
14
+ `gem 'ince-api'`
15
+
16
+ After doing bundle install, you should have the gem installed in your bundle.
17
+
18
+ ## Generating Access Token
19
+ In order to access 1nce API you need to add new API user in 1nce Admin panel.
20
+
21
+ If you want to authenticate and obtain Access Token you need to run following code
22
+
23
+ ```ruby
24
+ InceApi::CreateAccessToken.new(username: '<<YOUR USERNAME>>',
25
+ password: '<<YOUR PASSWORD>>').create_token
26
+ ```
27
+ which will return data of following structure
28
+
29
+ `{"status_code"=>200, "access_token"=>"eyJpZHRvoiZXl[..]hTXp0dWHpBIn0=", "token_type"=>"bearer", "expires_in"=>3600, "userId"=>"user", "scope"=>"all"}`
30
+
31
+ or
32
+
33
+ `{"statusCode"=>400, "errorCode"=>"CognitoAuthenticationError", "message"=>"Incorrect username or password."}`
34
+
35
+ if authentication failed
36
+
37
+ ## Getting SIM values
38
+
39
+ If you want to retrieve list of your SIM card you need to use the Access Token generated before. You can pass params hash - according to [DOCS](https://help.1nce.com/dev-hub/reference/general-sim#getsimsusingget)
40
+
41
+ ```ruby
42
+ token = InceApi::CreateAccessToken.new(username: '<<YOUR USERNAME>>', password: '<<YOUR PASSWORD>>').create_token['access_token']
43
+ sims = InceApi::GetSims.new(access_token: token, params: <<PARAM HASH>>).sims
44
+ ```
45
+
46
+ which will return data of following structure
47
+
48
+ `[{"iccid"=>"XXXXXXXXXXXXXXX", "imsi"=>"XXXXXXXXXXXXXX", "msisdn"=>"XXXXXXXXXXXXXXXXX", "imei"=>"XXXXXXXXXXXXXX", "imei_lock"=>false, "status"=>"Enabled", "activation_date"=>"2021-08-26T12:13:06.000+0000", "ip_address"=>"XX.XXX.XXX.X", "current_quota"=>500, "quota_status"=>{"id"=>0, "description"=>"More than 20% available"}, "current_quota_SMS"=>250, "quota_status_SMS"=>{"id"=>0, "description"=>"More than 20% available"}},[...]`
49
+
50
+ You can also fetch single card
51
+ ```ruby
52
+ token = InceApi::CreateAccessToken.new(username: '<<YOUR USERNAME>>', password: '<<YOUR PASSWORD>>').create_token['access_token']
53
+ sims = InceApi::GetSim.new(access_token: token, iccid: 'XXXXXXXXX').sim
54
+ ```
data/ince-api.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ince-api'
3
+ s.version = '0.0.3'
4
+ s.summary = "1nce API wrapper"
5
+ s.description = "A simple wrapper for 1nce API"
6
+ s.authors = ["Stanislaw Zawadzki"]
7
+ s.email = 'st.zawadzki@gmail.com'
8
+ s.homepage = 'https://rubygems.org/gems/ince-api'
9
+ s.license = 'MIT'
10
+
11
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+ s.require_paths = ['lib']
14
+ s.license = 'MIT'
15
+ s.add_dependency 'uri', '~> 0.11'
16
+ s.add_dependency 'net-http', '~> 0.2'
17
+ s.add_dependency 'openssl', '~> 2.2'
18
+ s.add_dependency 'base64', '~> 0.1'
19
+ s.add_development_dependency 'pry', '~> 0.13'
20
+ end
21
+
data/lib/ince-api.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ require_relative 'ince_api/create_access_token'
7
+ require_relative 'ince_api/get_sims'
8
+ require_relative 'ince_api/get_sim'
9
+ require_relative 'ince_api/single_sim_configuration'
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+
3
+ module InceApi
4
+ class CreateAccessToken
5
+ def initialize(username:, password:)
6
+ @username = username
7
+ @password = password
8
+ end
9
+
10
+ URL = URI("https://api.1nce.com/management-api/oauth/token")
11
+
12
+ def create_token
13
+ response = connection.request(request)
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ def request
18
+ 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
+ end
24
+ end
25
+
26
+ def connection
27
+ @connection ||= Net::HTTP.new(URL.host, URL.port).tap do |http|
28
+ http.use_ssl = true
29
+ end
30
+ end
31
+
32
+ def encoded_credentials
33
+ Base64.encode64("#{@username}:#{@password}").strip
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module InceApi
2
+ class GetSim
3
+ def initialize(access_token:, iccid:)
4
+ @access_token = access_token
5
+ @iccid = iccid
6
+ end
7
+
8
+ def sim
9
+ response = connection.request(request)
10
+ JSON.parse(response.body)
11
+ end
12
+
13
+ private
14
+
15
+ def url
16
+ @url ||= URI("https://api.1nce.com/management-api/v1/sims/#{@iccid}")
17
+ end
18
+
19
+ def connection
20
+ @connection ||= Net::HTTP.new(url.host, url.port).tap do |http|
21
+ http.use_ssl = true
22
+ end
23
+ end
24
+
25
+ def request
26
+ Net::HTTP::Get.new(url).tap do |request|
27
+ request["Accept"] = 'application/json'
28
+ request['Authorization'] = "Bearer #{@access_token}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ module InceApi
2
+ class GetSims
3
+ def initialize(access_token:, params: {})
4
+ @access_token = access_token
5
+ @params = params
6
+ end
7
+
8
+ def sims
9
+ response = connection.request(request)
10
+ JSON.parse(response.body)
11
+ end
12
+
13
+ private
14
+
15
+ ALLOWED_KEYS = %i(page pageSize q sort)
16
+ def params_query
17
+ URI.encode_www_form @params.slice(*ALLOWED_KEYS)
18
+ end
19
+
20
+ def url
21
+ @url ||= URI("https://api.1nce.com/management-api/v1/sims?#{params_query}")
22
+ end
23
+
24
+ def connection
25
+ @connection ||= Net::HTTP.new(url.host, url.port).tap do |http|
26
+ http.use_ssl = true
27
+ end
28
+ end
29
+
30
+ def request
31
+ Net::HTTP::Get.new(url).tap do |request|
32
+ request["Accept"] = 'application/json'
33
+ request['Authorization'] = "Bearer #{@access_token}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ module InceApi
2
+ class SingleSimConfiguration
3
+ def initialize(access_token:, iccid:, params:{})
4
+ @access_token = access_token
5
+ @iccid = iccid
6
+ @params = params
7
+ end
8
+
9
+ def update
10
+ response = connection.request(request)
11
+ response.code.to_i == 200 ? allowed_params.merge(status: 'OK') : { status: 'FAILED', error_code: response.code.to_i}
12
+ end
13
+
14
+ private
15
+
16
+ ALLOWED_KEYS = %i(label imei_lock status)
17
+ def allowed_params
18
+ @params.slice(*ALLOWED_KEYS)
19
+ end
20
+
21
+ def url
22
+ @url ||= URI("https://api.1nce.com/management-api/v1/sims/#{@iccid}")
23
+ end
24
+
25
+ def connection
26
+ @connection ||= Net::HTTP.new(url.host, url.port).tap do |http|
27
+ http.use_ssl = true
28
+ end
29
+ end
30
+
31
+ def request
32
+ Net::HTTP::Put.new(url).tap do |request|
33
+ request.body = allowed_params.to_json
34
+ request["Accept"] = 'application/json'
35
+ request["Content-Type"] = 'application/json;charset=UTF-8'
36
+ request['Authorization'] = "Bearer #{@access_token}"
37
+ end
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ince-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Stanislaw Zawadzki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: openssl
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: base64
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ description: A simple wrapper for 1nce API
84
+ email: st.zawadzki@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - README.md
90
+ - ince-api.gemspec
91
+ - lib/ince-api.rb
92
+ - lib/ince_api/create_access_token.rb
93
+ - lib/ince_api/get_sim.rb
94
+ - lib/ince_api/get_sims.rb
95
+ - lib/ince_api/single_sim_configuration.rb
96
+ homepage: https://rubygems.org/gems/ince-api
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.1.4
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: 1nce API wrapper
119
+ test_files: []