moki_ruby 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: c0a94a38cb0b659e29af3ca6bc390e3b9cb78dd4
4
- data.tar.gz: 0209ee2b6262b17e228d0ba671672c92400af57a
3
+ metadata.gz: f5ba3120c5be2062512bc20651093e5402fd3fdc
4
+ data.tar.gz: f1e93594ead22b828771831e598b92563ba41424
5
5
  SHA512:
6
- metadata.gz: 82bc152c026cfe0a9fe5333c2a7b58da1ff675d73c787c84ea2a48b4eb7afabff579797057fdf51db81b07b38df11b9e57306602b5850b4cb01a016ab167dd7e
7
- data.tar.gz: ca891aa084ef3673b5b34275228ac2b8424550d3dca0112468ef2e2f3197de0514b1d448f87e8802fd039df15dc2378296a8c679479225c93aed6fbed44fad2a
6
+ metadata.gz: 9123325638bc9404e6daec6ded483abeb8466337419a4c4bccb22f08eaade74b3d831891882656f5c8d43ac7905675b65e4c67a16f1d9b10ea6ee2ca221d8705
7
+ data.tar.gz: 752c6cef9f5181924164baab86792c92913bcb76bdae42f11af7a232e8b9365b9f847969fca10c4d75caa6ec4e5c67ffd74c7b5aa58bcff1903e7c4b817eeacf
data/Gemfile.lock CHANGED
@@ -1,28 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moki_ruby (0.0.1)
4
+ moki_ruby (0.0.3)
5
5
  celluloid
6
6
  celluloid-io
7
7
  faraday
8
8
  faraday_middleware
9
9
  hashie
10
+ require_all
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
15
  celluloid (0.16.0)
15
16
  timers (~> 4.0.0)
16
- celluloid-io (0.16.1)
17
+ celluloid-io (0.16.2)
17
18
  celluloid (>= 0.16.0)
18
- nio4r (>= 1.0.0)
19
+ nio4r (>= 1.1.0)
19
20
  coderay (1.1.0)
20
21
  diff-lcs (1.2.5)
21
22
  faraday (0.9.1)
22
23
  multipart-post (>= 1.2, < 3)
23
24
  faraday_middleware (0.9.1)
24
25
  faraday (>= 0.7.4, < 0.10)
25
- hashie (3.3.2)
26
+ hashie (3.4.0)
26
27
  hitimes (1.2.2)
27
28
  method_source (0.8.2)
28
29
  multipart-post (2.0.0)
@@ -32,6 +33,7 @@ GEM
32
33
  method_source (~> 0.8.1)
33
34
  slop (~> 3.4)
34
35
  rake (10.4.2)
36
+ require_all (1.3.2)
35
37
  rspec (3.2.0)
36
38
  rspec-core (~> 3.2.0)
37
39
  rspec-expectations (~> 3.2.0)
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  [![travis-status](https://travis-ci.org/bellycard/moki_ruby.svg)](https://travis-ci.org/bellycard/moki_ruby) [![Gem
4
4
  Version](https://badge.fury.io/rb/moki_ruby.svg)](http://badge.fury.io/rb/moki_ruby)
5
5
 
6
- A ruby gem for interacting with the Moki API, as a part of Moki Total
7
- Control and Moki Management.
6
+ A ruby gem for interacting with the Moki API, as a part of
7
+ [Moki Total Control](http://www.moki.com) and Moki Management.
8
8
 
9
9
  ## Installation
10
10
 
@@ -69,6 +69,21 @@ Using this device, there are several methods available:
69
69
  - `device.get_action(action_id)` will take in an `id` from an `Action`
70
70
  object, and return an updated `Action` object.
71
71
 
72
+ ## To do
73
+
74
+ - Handle cases where device is not found
75
+ - Handle error cases
76
+ - Confirm if profile is on device before adding/removing
77
+ - Confirm if app is on device before installing
78
+ - Add new Moki endpoints
79
+
80
+ ## Special Thanks
81
+
82
+ Thank you to the Moki team ([GitHub](https://github.com/MokiMobility)),
83
+ especially [Jared](https://github.com/jaredblake),
84
+ [Sam](https://github.com/mokiSam), and
85
+ [Sam](https://github.com/sroskelley).
86
+
72
87
  ## Contributing
73
88
 
74
89
  1. Fork it ( https://github.com/bellycard/moki_ruby/fork )
data/lib/moki_ruby.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "moki_ruby/version"
1
+ require 'require_all'
2
+ require_rel "./"
2
3
 
3
4
  module MokiRuby
4
5
  def self.ios_profiles
@@ -1,33 +1,35 @@
1
- class Action
2
- attr_accessor :id, :last_seen, :action, :status, :client_name, :item_name, :third_party_user, :payload, :note
1
+ module MokiRuby
2
+ class Action
3
+ attr_accessor :id, :last_seen, :action, :status, :client_name, :item_name, :third_party_user, :payload, :note
3
4
 
4
- def self.from_hash(input_hash)
5
- new_action = self.new
5
+ def self.from_hash(input_hash)
6
+ new_action = self.new
6
7
 
7
- new_action.id = input_hash["id"]
8
- new_action.last_seen = input_hash["lastSeen"]
9
- new_action.action = input_hash["action"]
10
- new_action.status = input_hash["status"]
11
- new_action.client_name = input_hash["clientName"]
12
- new_action.item_name = input_hash["itemName"]
13
- new_action.third_party_user = input_hash["thirdPartyUser"]
14
- new_action.payload = input_hash["payload"]
15
- new_action.note = input_hash["note"]
8
+ new_action.id = input_hash["id"]
9
+ new_action.last_seen = input_hash["lastSeen"]
10
+ new_action.action = input_hash["action"]
11
+ new_action.status = input_hash["status"]
12
+ new_action.client_name = input_hash["clientName"]
13
+ new_action.item_name = input_hash["itemName"]
14
+ new_action.third_party_user = input_hash["thirdPartyUser"]
15
+ new_action.payload = input_hash["payload"]
16
+ new_action.note = input_hash["note"]
16
17
 
17
- new_action
18
- end
18
+ new_action
19
+ end
19
20
 
20
- def to_hash
21
- {
22
- "id" => self.id,
23
- "lastSeen" => self.last_seen,
24
- "action" => self.action,
25
- "status" => self.status,
26
- "clientName" => self.client_name,
27
- "itemName" => self.item_name,
28
- "thirdPartyUser" => self.third_party_user,
29
- "payload" => self.payload,
30
- "note" => self.note
31
- }
21
+ def to_hash
22
+ {
23
+ "id" => self.id,
24
+ "lastSeen" => self.last_seen,
25
+ "action" => self.action,
26
+ "status" => self.status,
27
+ "clientName" => self.client_name,
28
+ "itemName" => self.item_name,
29
+ "thirdPartyUser" => self.third_party_user,
30
+ "payload" => self.payload,
31
+ "note" => self.note
32
+ }
33
+ end
32
34
  end
33
35
  end
@@ -1,20 +1,22 @@
1
- class DeviceManagedApp
2
- attr_accessor :status, :app_identifier, :management_flags
1
+ module MokiRuby
2
+ class DeviceManagedApp
3
+ attr_accessor :status, :app_identifier, :management_flags
3
4
 
4
- def self.from_hash(input_hash)
5
- new_app = self.new
6
- new_app.status = input_hash['Status']
7
- new_app.app_identifier = input_hash['appIdentifier']
8
- new_app.management_flags = input_hash['ManagementFlags']
5
+ def self.from_hash(input_hash)
6
+ new_app = self.new
7
+ new_app.status = input_hash['Status']
8
+ new_app.app_identifier = input_hash['appIdentifier']
9
+ new_app.management_flags = input_hash['ManagementFlags']
9
10
 
10
- new_app
11
- end
11
+ new_app
12
+ end
12
13
 
13
- def to_hash
14
- {
15
- "Status" => self.status,
16
- "appIdentifier" => self.app_identifier,
17
- "ManagementFlags" => self.management_flags
18
- }
14
+ def to_hash
15
+ {
16
+ "Status" => self.status,
17
+ "appIdentifier" => self.app_identifier,
18
+ "ManagementFlags" => self.management_flags
19
+ }
20
+ end
19
21
  end
20
22
  end
@@ -1,46 +1,48 @@
1
- class IOSProfile
2
- attr_accessor :id, :last_seen, :name, :display_name, :description, :identifier
1
+ module MokiRuby
2
+ class IOSProfile
3
+ attr_accessor :id, :last_seen, :name, :display_name, :description, :identifier
3
4
 
4
- def self.from_hash(input_hash)
5
- new_profile = self.new
6
- new_profile.id = input_hash["id"]
7
- new_profile.last_seen = input_hash["lastSeen"]
8
- new_profile.name = input_hash["name"]
9
- new_profile.display_name = input_hash["displayName"]
10
- new_profile.description = input_hash["description"]
11
- new_profile.identifier = input_hash["identifier"]
5
+ def self.from_hash(input_hash)
6
+ new_profile = self.new
7
+ new_profile.id = input_hash["id"]
8
+ new_profile.last_seen = input_hash["lastSeen"]
9
+ new_profile.name = input_hash["name"]
10
+ new_profile.display_name = input_hash["displayName"]
11
+ new_profile.description = input_hash["description"]
12
+ new_profile.identifier = input_hash["identifier"]
12
13
 
13
- new_profile
14
- end
14
+ new_profile
15
+ end
15
16
 
16
- def to_hash
17
- {
18
- "id" => self.id,
19
- "lastSeen" => self.last_seen,
20
- "name" => self.name,
21
- "displayName" => self.display_name,
22
- "description" => self.description,
23
- "identifier" => self.identifier
24
- }
25
- end
17
+ def to_hash
18
+ {
19
+ "id" => self.id,
20
+ "lastSeen" => self.last_seen,
21
+ "name" => self.name,
22
+ "displayName" => self.display_name,
23
+ "description" => self.description,
24
+ "identifier" => self.identifier
25
+ }
26
+ end
26
27
 
27
- def install_hash
28
- actionable_hash.merge({ "action" => "installprofile",
29
- "payload" => "{#{ self.id }}" })
30
- end
28
+ def install_hash
29
+ actionable_hash.merge({ "action" => "installprofile",
30
+ "payload" => "{#{ self.id }}" })
31
+ end
31
32
 
32
- def removal_hash
33
- actionable_hash.merge({ "action" => "removeprofile",
34
- "payload" => "{#{ self.identifier }}" })
35
- end
33
+ def removal_hash
34
+ actionable_hash.merge({ "action" => "removeprofile",
35
+ "payload" => "{#{ self.identifier }}" })
36
+ end
36
37
 
37
- private
38
- def actionable_hash
39
- {
40
- "thirdPartyUser" => "moki_ruby",
41
- "clientName" => "MokiRuby",
42
- "itemName" => self.name,
43
- "notify" => true
44
- }
38
+ private
39
+ def actionable_hash
40
+ {
41
+ "thirdPartyUser" => "moki_ruby",
42
+ "clientName" => "MokiRuby",
43
+ "itemName" => self.name,
44
+ "notify" => true
45
+ }
46
+ end
45
47
  end
46
48
  end
@@ -0,0 +1,118 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'celluloid/io'
4
+ require 'moki_ruby/future_wrapper'
5
+ require 'hashie'
6
+
7
+ module MokiRuby
8
+ class MokiAPI
9
+ include Celluloid::IO
10
+ BASE_URL = '/rest/v1/api/tenants/'
11
+
12
+ def self.ios_profiles
13
+ issue_request(:get, full_url('/iosprofiles'), {})
14
+ end
15
+
16
+ def self.device_profile_list(device_id)
17
+ issue_request(:get, full_url("/devices/#{ device_id }/profiles"), {})
18
+ end
19
+
20
+ def self.tenant_managed_app_list
21
+ issue_request(:get, full_url('/iosmanagedapps'), {})
22
+ end
23
+
24
+ def self.device_managed_app_list(device_id)
25
+ issue_request(:get, full_url("/devices/#{ device_id }/managedapps"), {})
26
+ end
27
+
28
+ def self.perform_action(device_id, body_hash)
29
+ issue_request(:put, full_url("/devices/#{ device_id }/actions"), body_hash)
30
+ end
31
+
32
+ def self.action(device_id, action_id)
33
+ issue_request(:get, full_url("/devices/#{ device_id }/actions/#{ action_id }"), {})
34
+ end
35
+
36
+ def self.full_url(path)
37
+ raise "No Moki URL Provided. Set ENV['MOKI_API_URL']." if ENV['MOKI_API_URL'].nil? || ENV['MOKI_API_URL'].empty?
38
+ raise "No Tenant ID Provided. Set ENV['MOKI_TENANT_ID']." if ENV['MOKI_TENANT_ID'].nil? || ENV['MOKI_TENANT_ID'].empty?
39
+
40
+ ENV['MOKI_API_URL'] + BASE_URL + ENV['MOKI_TENANT_ID'] + path
41
+ end
42
+
43
+ def self.issue_request(method, url, options)
44
+ raise "No API Key Provided. Set ENV['MOKI_API_KEY']." if ENV['MOKI_API_KEY'].nil? || ENV['MOKI_API_KEY'].empty?
45
+
46
+ future = Celluloid::Future.new do
47
+ begin
48
+ log_request(method, url)
49
+ response = conn.send(method, url, options) do |request|
50
+ request.headers = request.headers.merge(headers)
51
+ end
52
+ to_return_type response
53
+ rescue => e
54
+ Honeybadger.notify(e, context: { method: method,
55
+ url: url,
56
+ options: options,
57
+ response_status: response.try(:status),
58
+ response_body: response.try(:body) }) if defined?(Honeybadger)
59
+ raise e
60
+ end
61
+ end
62
+ future.extend(FutureWrapper)
63
+ end
64
+
65
+ def issue_request(method, url, options)
66
+ self.class.issue_request(method, url, options)
67
+ end
68
+
69
+ private
70
+ def self.to_return_type response
71
+ begin
72
+ Hashie::Mash.new({
73
+ body: JSON.parse(response.body),
74
+ status: response.status,
75
+ headers: response.headers
76
+ })
77
+ rescue
78
+ response
79
+ end
80
+ end
81
+
82
+ def self.conn
83
+ connection = Faraday.new do |conn|
84
+ conn.request :json
85
+ conn.adapter Faraday.default_adapter
86
+ end
87
+ connection
88
+ end
89
+
90
+ def self.headers
91
+ {
92
+ "X-Moki-TenantAPIToken" => ENV['MOKI_API_KEY']
93
+ }
94
+ end
95
+
96
+ def self.log_request(method, url)
97
+ logger = if defined?(Rails)
98
+ Rails.logger
99
+ elsif defined?(Napa::Logger)
100
+ Napa::Logger.logger
101
+ else
102
+ nil
103
+ end
104
+
105
+ return unless logger
106
+
107
+ data = { moki_api_request:
108
+ {
109
+ message: "Calling Moki API URL #{ url }",
110
+ request_method: method,
111
+ request_url: url,
112
+ }
113
+ }
114
+
115
+ logger.info(data.as_json)
116
+ end
117
+ end
118
+ end
@@ -1,56 +1,58 @@
1
- class TenantManagedApp
2
- attr_accessor :id, :last_seen, :name, :identifier, :version,
3
- :management_flags, :itunes_store_id, :manifest_url
1
+ module MokiRuby
2
+ class TenantManagedApp
3
+ attr_accessor :id, :last_seen, :name, :identifier, :version,
4
+ :management_flags, :itunes_store_id, :manifest_url
4
5
 
5
- def self.from_hash(input_hash)
6
- new_app = self.new
7
- new_app.id = input_hash["id"]
8
- new_app.last_seen = input_hash["lastSeen"]
9
- new_app.name = input_hash["name"]
10
- new_app.identifier = input_hash["identifier"]
11
- new_app.version = input_hash["version"]
12
- new_app.management_flags = input_hash["ManagementFlags"]
13
- new_app.itunes_store_id = input_hash["iTunesStoreID"]
14
- new_app.manifest_url = input_hash["ManifestURL"]
6
+ def self.from_hash(input_hash)
7
+ new_app = self.new
8
+ new_app.id = input_hash["id"]
9
+ new_app.last_seen = input_hash["lastSeen"]
10
+ new_app.name = input_hash["name"]
11
+ new_app.identifier = input_hash["identifier"]
12
+ new_app.version = input_hash["version"]
13
+ new_app.management_flags = input_hash["ManagementFlags"]
14
+ new_app.itunes_store_id = input_hash["iTunesStoreID"]
15
+ new_app.manifest_url = input_hash["ManifestURL"]
15
16
 
16
- new_app
17
- end
17
+ new_app
18
+ end
18
19
 
19
- def to_hash
20
- { "id" => self.id,
21
- "lastSeen" => self.last_seen,
22
- "name" => self.name,
23
- "identifier" => self.identifier,
24
- "version" => self.version,
25
- "ManagementFlags" => self.management_flags,
26
- "iTunesStoreID" => self.itunes_store_id,
27
- "ManifestURL" => self.manifest_url }
28
- end
20
+ def to_hash
21
+ { "id" => self.id,
22
+ "lastSeen" => self.last_seen,
23
+ "name" => self.name,
24
+ "identifier" => self.identifier,
25
+ "version" => self.version,
26
+ "ManagementFlags" => self.management_flags,
27
+ "iTunesStoreID" => self.itunes_store_id,
28
+ "ManifestURL" => self.manifest_url }
29
+ end
29
30
 
30
- def install_hash
31
- {
32
- "action" => "install_app",
33
- "thirdPartyUser" => "moki_ruby",
34
- "clientName" => "MokiRuby",
35
- "itemName" => self.name,
36
- "notify" => true,
37
- "payload" => {
38
- "ManagementFlags" => self.management_flag,
39
- "identifier" => self.identifier,
40
- "version" => self.version
41
- }.merge(self.external_locator_hash)
42
- }
43
- end
31
+ def install_hash
32
+ {
33
+ "action" => "install_app",
34
+ "thirdPartyUser" => "moki_ruby",
35
+ "clientName" => "MokiRuby",
36
+ "itemName" => self.name,
37
+ "notify" => true,
38
+ "payload" => {
39
+ "ManagementFlags" => self.management_flag,
40
+ "identifier" => self.identifier,
41
+ "version" => self.version
42
+ }.merge(self.external_locator_hash)
43
+ }
44
+ end
44
45
 
45
- def management_flag
46
- (!manifest_url.nil? && manifest_url != "") ? 1 : 0
47
- end
46
+ def management_flag
47
+ (!manifest_url.nil? && manifest_url != "") ? 1 : 0
48
+ end
48
49
 
49
- def external_locator_hash
50
- if manifest_url && manifest_url != ""
51
- { "ManifestURL" => manifest_url }
52
- else
53
- { "iTunesStoreID" => itunes_store_id }
50
+ def external_locator_hash
51
+ if manifest_url && manifest_url != ""
52
+ { "ManifestURL" => manifest_url }
53
+ else
54
+ { "iTunesStoreID" => itunes_store_id }
55
+ end
54
56
  end
55
57
  end
56
58
  end
@@ -1,3 +1,3 @@
1
1
  module MokiRuby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/moki_ruby.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'celluloid'
24
24
  spec.add_dependency 'celluloid-io'
25
25
  spec.add_dependency 'hashie'
26
+ spec.add_dependency 'require_all'
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.6"
28
29
  spec.add_development_dependency "rake"
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'moki_api'
2
+ require 'moki_ruby/moki_api'
3
3
 
4
4
  describe MokiAPI do
5
5
  describe "missing env variable" do
data/spec/spec_helper.rb CHANGED
@@ -19,3 +19,5 @@ RSpec.configure do |config|
19
19
  config.order = :random
20
20
  Kernel.srand config.seed
21
21
  end
22
+
23
+ include MokiRuby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moki_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Springer
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: require_all
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -151,13 +165,13 @@ files:
151
165
  - LICENSE.txt
152
166
  - README.md
153
167
  - Rakefile
154
- - lib/future_wrapper.rb
155
- - lib/moki_api.rb
156
168
  - lib/moki_ruby.rb
157
169
  - lib/moki_ruby/action.rb
158
170
  - lib/moki_ruby/device.rb
159
171
  - lib/moki_ruby/device_managed_app.rb
172
+ - lib/moki_ruby/future_wrapper.rb
160
173
  - lib/moki_ruby/iosprofile.rb
174
+ - lib/moki_ruby/moki_api.rb
161
175
  - lib/moki_ruby/tenant_managed_app.rb
162
176
  - lib/moki_ruby/version.rb
163
177
  - moki_ruby.gemspec
data/lib/moki_api.rb DELETED
@@ -1,116 +0,0 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
- require 'celluloid/io'
4
- require 'future_wrapper'
5
- require 'hashie'
6
-
7
- class MokiAPI
8
- include Celluloid::IO
9
- BASE_URL = '/rest/v1/api/tenants/'
10
-
11
- def self.ios_profiles
12
- issue_request(:get, full_url('/iosprofiles'), {})
13
- end
14
-
15
- def self.device_profile_list(device_id)
16
- issue_request(:get, full_url("/devices/#{ device_id }/profiles"), {})
17
- end
18
-
19
- def self.tenant_managed_app_list
20
- issue_request(:get, full_url('/iosmanagedapps'), {})
21
- end
22
-
23
- def self.device_managed_app_list(device_id)
24
- issue_request(:get, full_url("/devices/#{ device_id }/managedapps"), {})
25
- end
26
-
27
- def self.perform_action(device_id, body_hash)
28
- issue_request(:put, full_url("/devices/#{ device_id }/actions"), body_hash)
29
- end
30
-
31
- def self.action(device_id, action_id)
32
- issue_request(:get, full_url("/devices/#{ device_id }/actions/#{ action_id }"), {})
33
- end
34
-
35
- def self.full_url(path)
36
- raise "No Moki URL Provided. Set ENV['MOKI_API_URL']." if ENV['MOKI_API_URL'].nil? || ENV['MOKI_API_URL'].empty?
37
- raise "No Tenant ID Provided. Set ENV['MOKI_TENANT_ID']." if ENV['MOKI_TENANT_ID'].nil? || ENV['MOKI_TENANT_ID'].empty?
38
-
39
- ENV['MOKI_API_URL'] + BASE_URL + ENV['MOKI_TENANT_ID'] + path
40
- end
41
-
42
- def self.issue_request(method, url, options)
43
- raise "No API Key Provided. Set ENV['MOKI_API_KEY']." if ENV['MOKI_API_KEY'].nil? || ENV['MOKI_API_KEY'].empty?
44
-
45
- future = Celluloid::Future.new do
46
- begin
47
- log_request(method, url)
48
- response = conn.send(method, url, options) do |request|
49
- request.headers = request.headers.merge(headers)
50
- end
51
- to_return_type response
52
- rescue => e
53
- Honeybadger.notify(e, context: { method: method,
54
- url: url,
55
- options: options,
56
- response_status: response.try(:status),
57
- response_body: response.try(:body) }) if defined?(Honeybadger)
58
- raise e
59
- end
60
- end
61
- future.extend(FutureWrapper)
62
- end
63
-
64
- def issue_request(method, url, options)
65
- self.class.issue_request(method, url, options)
66
- end
67
-
68
- private
69
- def self.to_return_type response
70
- begin
71
- Hashie::Mash.new({
72
- body: JSON.parse(response.body),
73
- status: response.status,
74
- headers: response.headers
75
- })
76
- rescue
77
- response
78
- end
79
- end
80
-
81
- def self.conn
82
- connection = Faraday.new do |conn|
83
- conn.request :json
84
- conn.adapter Faraday.default_adapter
85
- end
86
- connection
87
- end
88
-
89
- def self.headers
90
- {
91
- "X-Moki-TenantAPIToken" => ENV['MOKI_API_KEY']
92
- }
93
- end
94
-
95
- def self.log_request(method, url)
96
- logger = if defined?(Rails)
97
- Rails.logger
98
- elsif defined?(Napa::Logger)
99
- Napa::Logger.logger
100
- else
101
- nil
102
- end
103
-
104
- return unless logger
105
-
106
- data = { moki_api_request:
107
- {
108
- message: "Calling Moki API URL #{ url }",
109
- request_method: method,
110
- request_url: url,
111
- }
112
- }
113
-
114
- logger.info(data.as_json)
115
- end
116
- end