alula-ruby 0.53.0 → 0.54.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fed2d4120549496df3eff6a4e9855ab8b04037ed93054223cd2aca95f49297c0
4
- data.tar.gz: 2d5487298cee2c7d6a7fd92c8324185ea132a3f90ee5cc57bdd6cc1568ad151e
3
+ metadata.gz: 5fe8c069cbf129ad7f52be697c4159cad1e78ef655316eae5ee26de2e184a8df
4
+ data.tar.gz: cdcda384977cae4869f73892f8a0f309f2965be5b180b56500f0453dc1da27df
5
5
  SHA512:
6
- metadata.gz: 3b40279544744c8a858c64edf71ced4167a1e0078c70a621b0edbb1fdf7831455ffc840b0b3481e4f8ba7ed716f5eaf4d2e4126af1ea9296f70a016cb8417d0d
7
- data.tar.gz: e3397428375e4c52389c0850eeebd71eb3ee7ef0646b708f178e35c5beac24acc929443df673fb8a74ad53ad11c8fd488b7fe31f935b3aea8fd037f937f15eb3
6
+ metadata.gz: 7ff734d5a1ab9e49a77262d7f7b8aa05676bb526e123351f89dc4e6984f1b842fbb6b69502e8d54ddf0fb384d722d0fd23d02d0c1d052ccbc0a79bd16fd6feaf
7
+ data.tar.gz: b7cdcdeb6fd33066c52b8cd1f6a4ba274bfa4c793f14cc6165b547da5e32110d112135156c370d8aaf3a782e25f7c9406904697b4847730fd6c1387e99fea6c4
data/README.md CHANGED
@@ -42,17 +42,26 @@ creds = Alula::Oauth.authenticate(username: "a username", password: "a password"
42
42
  ## Configuring
43
43
 
44
44
  ```ruby
45
- Alula::Client.api_key = your API key
46
- Alula::Client.api_url = The environment URL you will be accessing
47
- Alula::Client.user_agent = A short name for your script/application
45
+ Alula::Client.config.api_key = your API key
46
+ Alula::Client.config.api_url = The environment URL you will be accessing
47
+ Alula::Client.config.user_agent = A short name for your script/application
48
48
  ```
49
+ -or-
50
+ ```ruby
51
+ Alula::Client.configure do |d|
52
+ c.api_key = your API key
53
+ c.api_url = The environment URL you will be accessing
54
+ c.user_agent = A short name for your script/application
55
+ end
56
+ ```
57
+ **Note:** You will also need to add the configuration option `customer_id` to access resources of the video API.
49
58
 
50
59
  ## Usage
51
60
 
52
61
  Once you have obtained an access token, configure the client to use that token. You should perform this initialization at the start of every request, and at the start of any thread that performs work. The Alula-Ruby client uses the `RequestStore` gem to stash its configuration data in `Thread.current`, so keep this limitation in mind.
53
62
 
54
63
  ```ruby
55
- Alula::Client.api_key = "your access token"
64
+ Alula::Client.config.api_key = "your access token"
56
65
  ```
57
66
 
58
67
  If you need to save any records, you will also need to tell the `Alula::Client` about your users' authorized role. Depending on the role certain fields may be writeable or protected. You can set your role one of 3 ways:
@@ -61,13 +70,10 @@ If you need to save any records, you will also need to tell the `Alula::Client`
61
70
  myself = Alula::Self.retrieve
62
71
 
63
72
  # The user role is inferred from the Alula::Self object
64
- Alula::Client.role = myself
73
+ Alula::Client.config.role = myself
65
74
 
66
75
  # Explicitly set the role via a role symbol
67
- Alula::Client.role = :dealer
68
-
69
- # Explicitly set the role via a u_type integer
70
- Alula::Client.u_type = 8
76
+ Alula::Client.config.role = :dealer
71
77
  ```
72
78
 
73
79
  Any method will do, you just need to perform one of these prior to attempting to save a resource. Role symbols map to uType resources. The Alula Gem supports the following roles & their corrisponding uType:
data/VERSION.md CHANGED
@@ -85,3 +85,4 @@
85
85
  | v0.51.0 | 2022-03-29 | Be able to delete Device Programs |
86
86
  | v0.52.0 | 2022-06-15 | Filter receiver connections based on station id |
87
87
  | v0.53.0 | 2022-06-15 | Filter feature plans on name |
88
+ | v0.54.0 | 2022-06-21 | Add support for devices from the video API |
data/alula.gemspec CHANGED
@@ -27,12 +27,13 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "httparty", "~> 0.18.1"
28
28
  spec.add_dependency 'request_store', '~> 1.0'
29
29
 
30
+ spec.add_development_dependency "activesupport"
30
31
  spec.add_development_dependency "bundler", "~> 2.0"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "nokogiri", "~> 1.10.3"
34
32
  spec.add_development_dependency "dotenv"
35
33
  spec.add_development_dependency "guard-rspec"
36
- spec.add_development_dependency "activesupport"
34
+ spec.add_development_dependency "nokogiri", "~> 1.10.3"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "simplecov", "~> 0.21.2"
37
38
  spec.add_development_dependency "timecop"
38
39
  end
@@ -41,4 +41,4 @@ module Alula
41
41
  end
42
42
  end
43
43
  end
44
- end
44
+ end
data/lib/alula/client.rb CHANGED
@@ -5,47 +5,24 @@ module Alula
5
5
  class Client
6
6
  include HTTParty
7
7
  class << self
8
- # Has pseudo accessors :api_key, :api_url, :user_agent, :debug
9
8
  DEFAULT_CUSTOM_OPTIONS = {
10
9
  omitRelationships: true
11
10
  }
12
11
 
13
- def request(http_method, resource_path, filters = {}, opts = {})
14
- ensure_api_key_set
15
- ensure_role_set if %i[patch post put].include? http_method
16
- ensure_method_allowable(http_method)
17
-
18
- raise Alula::NotConfiguredError, 'did you forget to set the Alula::Client.api_url config option?' unless api_url
19
-
20
- request_opts = {
21
- headers: {
22
- 'Authorization': "Bearer #{api_key}",
23
- 'User-Agent': "#{user_agent || 'No Agent Set'}/alula-ruby v#{Alula::VERSION}"
24
- }
25
- }.merge(opts)
12
+ def config
13
+ @_config ||= Alula::ClientConfiguration.new
14
+ end
26
15
 
27
- request_opts[:headers]['Content-Type'] = 'application/json' unless opts[:multipart]
28
- case http_method
29
- when :patch,
30
- :post
31
- request_opts[:body] = opts[:multipart] ? filters : JSON.generate(filters)
32
- when :get
33
- if resource_path.match(%r{^/rest})
34
- request_opts = request_opts.merge build_rest_options(filters)
35
- elsif resource_path.match(%r{^/rpc})
36
- request_opts = request_opts.merge build_rest_options(filters)
37
- end
38
- when :delete
39
- # Nothing special
40
- end
16
+ def configure
17
+ yield config
18
+ end
41
19
 
42
- if debug == true
43
- request_opts[:debug_output] = Alula.logger
44
- logger Alula.logger, :info
45
- end
20
+ def request(http_method, resource_path, filters = {}, opts = {})
21
+ validate_request!(http_method, resource_path)
22
+ request_opts = build_options(http_method, resource_path, filters, opts)
46
23
 
47
24
  # TODO: Handle network failures
48
- response = make_request(http_method, api_url + resource_path, request_opts)
25
+ response = make_request(http_method, config.api_url + resource_path, request_opts)
49
26
 
50
27
  begin
51
28
  resp = AlulaResponse.from_httparty_response(response)
@@ -57,62 +34,56 @@ module Alula
57
34
  resp
58
35
  end
59
36
 
60
- def make_request(http_method, full_url, request_opts)
61
- send(http_method, full_url, request_opts)
62
- end
63
-
64
- #
65
- # Using RequestStore so we're thread safe even with our non-thread-safe architecture :(
66
- %i[api_key api_url user_agent debug].each do |prop|
67
- define_method(prop) do
68
- RequestStore.store["alula_#{prop}"]
69
- end
70
-
71
- define_method("#{prop}=") do |value|
72
- RequestStore.store["alula_#{prop}"] = value
73
- end
74
- end
75
-
76
- #
77
- # Stash the user type as a role for us to infer from later
78
- # You can set a symbolized role via role = :user, or provide the string userType
79
- # We cast to a symbolized role for ease of use in consumers.
80
- def role=(user_type)
81
- unless user_type.is_a?(Symbol) || user_type.is_a?(String)
82
- raise Alula::InvalidRoleError, 'Role must be symbol or string'
83
- end
84
-
85
- RequestStore.store['alula_role'] = Util.underscore(user_type).to_sym
86
- end
37
+ private
87
38
 
88
- def role
89
- RequestStore.store['alula_role']
39
+ def validate_request!(http_method, resource_path)
40
+ config.ensure_api_key_set
41
+ config.ensure_api_url_set
42
+ config.ensure_customer_id_set if resource_path.match(%r{^/video})
43
+ ensure_method_allowable(http_method)
44
+ config.ensure_role_set if %i[patch post put].include? http_method
90
45
  end
91
46
 
92
- def ensure_api_key_set
93
- if api_key.nil?
94
- raise Alula::NotConfiguredError,
95
- 'Set your API access token before making requests with Alula::Client.api_key = {access_token}'
96
- end
47
+ def make_request(http_method, full_url, request_opts)
48
+ send(http_method, full_url, request_opts)
97
49
  end
98
50
 
99
51
  def ensure_method_allowable(http_method)
100
52
  unless %i[get post put patch delete].include?(http_method)
101
- raise "Unable to send a request with #{http_method} http method in #{self::OBJECT_NAME} class"
53
+ raise "Unable to send a request with #{http_method} http method"
102
54
  end
103
55
  end
104
56
 
105
- def ensure_role_set
106
- if role.nil?
107
- message = 'User role not configured! You must set '\
108
- 'Alula::Client.role '\
109
- 'before attempting to save any resources'
57
+ def build_options(http_method, resource_path, filters = {}, opts = {})
58
+ request_opts = {
59
+ headers: {
60
+ 'Authorization': "Bearer #{Alula::Client.config.api_key}",
61
+ 'User-Agent': "#{Alula::Client.config.user_agent || 'No Agent Set'}/alula-ruby v#{Alula::VERSION}"
62
+ }
63
+ }.merge(opts)
110
64
 
111
- raise Alula::NotConfiguredError, message
65
+ request_opts[:headers]['Content-Type'] = 'application/json' unless opts[:multipart]
66
+ case http_method
67
+ when :patch,
68
+ :post
69
+ request_opts[:body] = opts[:multipart] ? filters : JSON.generate(filters)
70
+ when :get
71
+ if resource_path.match(%r{^/(rest|rpc)})
72
+ request_opts = request_opts.merge build_rest_options(filters)
73
+ elsif resource_path.match(%r{^/video})
74
+ add_customer_id(request_opts)
75
+ end
76
+ when :delete
77
+ # Nothing special
112
78
  end
113
- end
114
79
 
115
- private
80
+ if Alula::Client.config.debug
81
+ request_opts[:debug_output] = Alula.logger
82
+ logger Alula.logger, :info
83
+ end
84
+
85
+ request_opts
86
+ end
116
87
 
117
88
  def build_rest_options(filters)
118
89
  request_opts = {}
@@ -137,6 +108,10 @@ module Alula
137
108
  def build_rpc_options(filters)
138
109
  filters
139
110
  end
111
+
112
+ def add_customer_id(request_opts)
113
+ request_opts[:query] = { 'customerId' => config.customer_id }
114
+ end
140
115
  end
141
116
  end
142
117
  end
@@ -0,0 +1,61 @@
1
+ module Alula
2
+ class ClientConfiguration
3
+ REQUEST_ATTRIBUTES = %i[api_key api_url debug customer_id user_agent]
4
+
5
+ # Using RequestStore so we're thread safe even with our non-thread-safe architecture :(
6
+ REQUEST_ATTRIBUTES.each do |prop|
7
+ define_method(prop) do
8
+ RequestStore.store["alula_#{prop}"]
9
+ end
10
+
11
+ define_method("#{prop}=") do |value|
12
+ RequestStore.store["alula_#{prop}"] = value
13
+ end
14
+ end
15
+
16
+ # Stash the user type as a role for us to infer from later
17
+ # You can set a symbolized role via role = :user, or provide the string userType
18
+ # We cast to a symbolized role for ease of use in consumers.
19
+ def role=(user_type)
20
+ unless user_type.is_a?(Symbol) || user_type.is_a?(String)
21
+ raise Alula::InvalidRoleError, 'Role must be symbol or string'
22
+ end
23
+
24
+ RequestStore.store['alula_role'] = Util.underscore(user_type).to_sym
25
+ end
26
+
27
+ def role
28
+ RequestStore.store['alula_role']
29
+ end
30
+
31
+ def ensure_api_key_set
32
+ if api_key.nil?
33
+ raise Alula::NotConfiguredError,
34
+ 'Set your API access token before making requests with Alula::Client.config.api_key = {access_token}'
35
+ end
36
+ end
37
+
38
+ def ensure_api_url_set
39
+ if api_url.nil?
40
+ raise Alula::NotConfiguredError, 'did you forget to set the Alula::Client.config.api_url config option?'
41
+ end
42
+ end
43
+
44
+ def ensure_customer_id_set
45
+ unless customer_id
46
+ raise Alula::NotConfiguredError,
47
+ 'Set your customer_id before making requests to the video API'
48
+ end
49
+ end
50
+
51
+ def ensure_role_set
52
+ if role.nil?
53
+ message = 'User role not configured! You must set '\
54
+ 'Alula::Client.config.role '\
55
+ 'before attempting to save any resources'
56
+
57
+ raise Alula::NotConfiguredError, message
58
+ end
59
+ end
60
+ end
61
+ end
@@ -11,14 +11,11 @@ module Alula
11
11
  base.include(InstanceMethods)
12
12
  end
13
13
 
14
-
15
14
  #
16
15
  # Class methods for defining how fields and types work
17
16
  # NOTE: We're not using real getters and setters here. I want the method signature
18
17
  # to match how most other Ruby class configuration is done, and that is with
19
18
  # simple methods that take params.
20
-
21
-
22
19
  def resource_path(name)
23
20
  @resource_path = name
24
21
  end
@@ -148,7 +145,7 @@ module Alula
148
145
  end
149
146
 
150
147
  def field_patchable?(opts, record_persisted)
151
- user_role = Alula::Client.role
148
+ user_role = Alula::Client.config.role
152
149
 
153
150
  # different permission arrays are used for updates vs creates
154
151
  perm_key = record_persisted == true ? :patchable_by : :creatable_by
@@ -0,0 +1,36 @@
1
+ module Alula
2
+ module Video
3
+ class BaseResource < Alula::ApiResource
4
+ extend Alula::ResourceAttributes
5
+
6
+ class << self
7
+ def api_name(name = nil)
8
+ if name
9
+ @api_name = name
10
+ elsif @api_name
11
+ @api_name
12
+ else
13
+ superclass.api_name
14
+ end
15
+ end
16
+
17
+ # Infer resource name from classname if not provided
18
+ def resource_name(name = nil)
19
+ if name
20
+ @resource_name = name
21
+ elsif @resource_name
22
+ @resource_name
23
+ else
24
+ @resource_name = self.name.split('::').last.downcase.to_sym
25
+ end
26
+ end
27
+
28
+ def resource_url(id = nil)
29
+ "/#{api_name}/v1/#{resource_name}/#{id}"
30
+ end
31
+ end
32
+
33
+ api_name :video
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ module Alula
2
+ module Video
3
+ class Device < Alula::Video::BaseResource
4
+ extend Alula::ApiOperations::Request
5
+
6
+ field :account_id, type: :string
7
+ field :active, type: :boolean
8
+ field :brand, type: :string
9
+ field :hardware_id, type: :string
10
+ field :manufacturer, type: :string
11
+ field :name, type: :string
12
+ field :serial_number, type: :string
13
+ field :verification_code, type: :string
14
+ end
15
+ end
16
+ end
data/lib/alula/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alula
4
- VERSION = '0.53.0'
4
+ VERSION = '0.54.0'
5
5
  end
data/lib/alula.rb CHANGED
@@ -21,8 +21,9 @@ require_relative 'alula/query_interface'
21
21
  require_relative 'alula/util'
22
22
  require_relative 'alula/rate_limit'
23
23
 
24
- require_relative 'alula/errors'
25
24
  require_relative 'alula/client'
25
+ require_relative 'alula/client_configuration'
26
+ require_relative 'alula/errors'
26
27
  require_relative 'alula/list_object'
27
28
  require_relative 'alula/oauth'
28
29
 
@@ -61,6 +62,9 @@ require_relative 'alula/resources/feature_planvideo'
61
62
  require_relative 'alula/resources/feature_price'
62
63
  require_relative 'alula/resources/feature_bysubject'
63
64
 
65
+ require_relative 'alula/resources/video/base_resource'
66
+ require_relative 'alula/resources/video/device'
67
+
64
68
  require_relative 'alula/procedures/device_cellular_history_proc'
65
69
  require_relative 'alula/procedures/device_rateplan_get_proc'
66
70
  require_relative 'alula/procedures/device_register_proc'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alula-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.53.0
4
+ version: 0.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Johnson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-15 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,33 +67,33 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '2.0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake
70
+ name: dotenv
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rspec
84
+ name: guard-rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '3.0'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '3.0'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: nokogiri
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,47 +109,47 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: 1.10.3
97
111
  - !ruby/object:Gem::Dependency
98
- name: dotenv
112
+ name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '10.0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '10.0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: guard-rspec
126
+ name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: '3.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: '3.0'
125
139
  - !ruby/object:Gem::Dependency
126
- name: activesupport
140
+ name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ">="
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '0'
145
+ version: 0.21.2
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ">="
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '0'
152
+ version: 0.21.2
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: timecop
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +201,7 @@ files:
187
201
  - lib/alula/api_operations/save.rb
188
202
  - lib/alula/api_resource.rb
189
203
  - lib/alula/client.rb
204
+ - lib/alula/client_configuration.rb
190
205
  - lib/alula/errors.rb
191
206
  - lib/alula/filter_builder.rb
192
207
  - lib/alula/helpers/device_attribute_translations.rb
@@ -250,6 +265,8 @@ files:
250
265
  - lib/alula/resources/user_preferences.rb
251
266
  - lib/alula/resources/user_pushtoken.rb
252
267
  - lib/alula/resources/user_videoprofile.rb
268
+ - lib/alula/resources/video/base_resource.rb
269
+ - lib/alula/resources/video/device.rb
253
270
  - lib/alula/rest_resource.rb
254
271
  - lib/alula/rpc_resource.rb
255
272
  - lib/alula/rpc_response.rb