syncwise_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/syncwise_api/client.rb +47 -0
- data/lib/syncwise_api/errors.rb +93 -0
- data/lib/syncwise_api/ext/core_ext.rb +176 -0
- data/lib/syncwise_api/ext/inflections.rb +66 -0
- data/lib/syncwise_api/ext/inflector/inflections.rb +177 -0
- data/lib/syncwise_api/ext/inflector_methods.rb +62 -0
- data/lib/syncwise_api/ext/string_encoding.rb +12 -0
- data/lib/syncwise_api/mixins/mixins.rb +1 -0
- data/lib/syncwise_api/mixins/request_builder.rb +23 -0
- data/lib/syncwise_api/mixins/request_sender.rb +11 -0
- data/lib/syncwise_api/mixins/request_signer.rb +20 -0
- data/lib/syncwise_api/requests/V1_0/assign_device_create.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/base.rb +115 -0
- data/lib/syncwise_api/requests/V1_0/device_details.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/device_list.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/device_settings_details.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/device_settings_edit.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/device_subscribe.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/device_unsubscribe.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/driver_speed_report.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/obd_vehicle_details.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/trip_event_details.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/user_login.rb +26 -0
- data/lib/syncwise_api/requests/V1_0/user_subscribe_settings_details.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/vehicle_gauge_information.rb +19 -0
- data/lib/syncwise_api/requests/V1_0/vehicle_idling_history.rb +19 -0
- data/lib/syncwise_api/requests/requests.rb +2 -0
- data/lib/syncwise_api/responses/V1_0/base.rb +35 -0
- data/lib/syncwise_api/responses/V1_0/standard.rb +9 -0
- data/lib/syncwise_api/responses/responses.rb +1 -0
- data/lib/syncwise_api/service_utils/crypto/hmac_sha256.rb +15 -0
- data/lib/syncwise_api/service_utils/encoders/base64.rb +16 -0
- data/lib/syncwise_api/service_utils/encoders/json.rb +21 -0
- data/lib/syncwise_api/service_utils/http.rb +34 -0
- data/lib/syncwise_api/service_utils/parsers/json.rb +55 -0
- data/lib/syncwise_api/service_utils/service_utils.rb +2 -0
- data/lib/syncwise_api/service_utils/time_stamper.rb +13 -0
- data/lib/syncwise_api/version.rb +3 -0
- data/lib/syncwise_api.rb +30 -0
- data/syncwise_api.gemspec +27 -0
- data/tester.rb +10 -0
- metadata +162 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module SyncwiseApi
|
4
|
+
module ServiceUtils
|
5
|
+
module HTTP
|
6
|
+
|
7
|
+
JSON_MIME = 'application/json'
|
8
|
+
|
9
|
+
# callback will receive the response body
|
10
|
+
def post(request_url_string, body, &callback)
|
11
|
+
uri = URI(request_url_string)
|
12
|
+
req = Net::HTTP::Post.new(uri)
|
13
|
+
req.body = body
|
14
|
+
req.content_type = JSON_MIME
|
15
|
+
req['Accept'] = JSON_MIME
|
16
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
17
|
+
begin
|
18
|
+
resp = http.request(req)
|
19
|
+
# throws HTTP error if response.class is not Net::HTTPSuccess
|
20
|
+
resp.value
|
21
|
+
callback.call(resp)
|
22
|
+
rescue SyncwiseApi::Errors::SyncwiseError => e
|
23
|
+
SyncwiseApi::LOGGER.error e
|
24
|
+
rescue => e
|
25
|
+
fail SyncwiseApi::Errors::HttpError.new(e, request_url_string)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module_function :post
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
|
3
|
+
module SyncwiseApi
|
4
|
+
module ServiceUtils
|
5
|
+
module Parsers
|
6
|
+
module JSON
|
7
|
+
|
8
|
+
def parse(json_string)
|
9
|
+
|
10
|
+
recursive_parse = true
|
11
|
+
parsed = ''
|
12
|
+
|
13
|
+
if !json_string.blank? && json_string.is_a?(String)
|
14
|
+
begin
|
15
|
+
parsed = Yajl::Parser.parse(json_string)
|
16
|
+
parsed = parsed.symbolize_keys if parsed.is_a?(Hash)
|
17
|
+
rescue => e
|
18
|
+
SyncwiseApi::Errors::JSONParseError.new(e)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
while recursive_parse
|
23
|
+
recursive_parse = sub_parse!(parsed)
|
24
|
+
end
|
25
|
+
|
26
|
+
parsed
|
27
|
+
end
|
28
|
+
|
29
|
+
module_function :parse
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.sub_parse!(hash)
|
34
|
+
had_to_sub_parse = false
|
35
|
+
if hash.is_a?(Hash)
|
36
|
+
hash.each do |k, v|
|
37
|
+
if json_as_string?(v)
|
38
|
+
had_to_sub_parse = true
|
39
|
+
hash[k] = parse(v)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
had_to_sub_parse
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.json_as_string?(value)
|
48
|
+
if value.is_a?(String)
|
49
|
+
value.include?('{') || value.include?('[')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/syncwise_api.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'connection_pool'
|
3
|
+
require_relative 'syncwise_api/version'
|
4
|
+
require_relative 'syncwise_api/errors'
|
5
|
+
require_relative 'syncwise_api/service_utils/service_utils'
|
6
|
+
require_relative 'syncwise_api/ext/core_ext'
|
7
|
+
require_relative 'syncwise_api/mixins/mixins'
|
8
|
+
require_relative 'syncwise_api/requests/requests'
|
9
|
+
require_relative 'syncwise_api/responses/responses'
|
10
|
+
require_relative 'syncwise_api/client'
|
11
|
+
|
12
|
+
module SyncwiseApi
|
13
|
+
LOGGER = Logger.new(STDERR)
|
14
|
+
|
15
|
+
def start(username, password, number_of_clients = 1)
|
16
|
+
@clients ||= ConnectionPool.new(size: number_of_clients, timeout: 5) { SyncwiseApi::Client.new(username, password)}
|
17
|
+
end
|
18
|
+
|
19
|
+
def make_request(action_code, params)
|
20
|
+
if @clients
|
21
|
+
@clients.with do |client|
|
22
|
+
client.make_request(action_code, params)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
puts 'You must first call SyncwiseAPI.start(username, password) before you can call SyncwiseApi.make_request.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module_function :start, :make_request
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'syncwise_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "syncwise_api"
|
8
|
+
spec.version = SyncwiseApi::VERSION
|
9
|
+
spec.authors = ["Brendten Eickstaedt"]
|
10
|
+
spec.email = ["brendten@brendteneickstaedt.com"]
|
11
|
+
spec.description = %q{Syncwise API library for Ruby}
|
12
|
+
spec.summary = %q{Syncwise API library for Ruby}
|
13
|
+
spec.homepage = "https://bitbucket.org/mavizon/syncwise_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'yajl-ruby', '~> 1.1.0'
|
22
|
+
spec.add_dependency 'connection_pool', '~> 1.0.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
end
|
data/tester.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syncwise_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendten Eickstaedt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yajl-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
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'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Syncwise API library for Ruby
|
84
|
+
email:
|
85
|
+
- brendten@brendteneickstaedt.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .ruby-gemset
|
92
|
+
- .ruby-version
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/syncwise_api.rb
|
98
|
+
- lib/syncwise_api/client.rb
|
99
|
+
- lib/syncwise_api/errors.rb
|
100
|
+
- lib/syncwise_api/ext/core_ext.rb
|
101
|
+
- lib/syncwise_api/ext/inflections.rb
|
102
|
+
- lib/syncwise_api/ext/inflector/inflections.rb
|
103
|
+
- lib/syncwise_api/ext/inflector_methods.rb
|
104
|
+
- lib/syncwise_api/ext/string_encoding.rb
|
105
|
+
- lib/syncwise_api/mixins/mixins.rb
|
106
|
+
- lib/syncwise_api/mixins/request_builder.rb
|
107
|
+
- lib/syncwise_api/mixins/request_sender.rb
|
108
|
+
- lib/syncwise_api/mixins/request_signer.rb
|
109
|
+
- lib/syncwise_api/requests/V1_0/assign_device_create.rb
|
110
|
+
- lib/syncwise_api/requests/V1_0/base.rb
|
111
|
+
- lib/syncwise_api/requests/V1_0/device_details.rb
|
112
|
+
- lib/syncwise_api/requests/V1_0/device_list.rb
|
113
|
+
- lib/syncwise_api/requests/V1_0/device_settings_details.rb
|
114
|
+
- lib/syncwise_api/requests/V1_0/device_settings_edit.rb
|
115
|
+
- lib/syncwise_api/requests/V1_0/device_subscribe.rb
|
116
|
+
- lib/syncwise_api/requests/V1_0/device_unsubscribe.rb
|
117
|
+
- lib/syncwise_api/requests/V1_0/driver_speed_report.rb
|
118
|
+
- lib/syncwise_api/requests/V1_0/obd_vehicle_details.rb
|
119
|
+
- lib/syncwise_api/requests/V1_0/trip_event_details.rb
|
120
|
+
- lib/syncwise_api/requests/V1_0/user_login.rb
|
121
|
+
- lib/syncwise_api/requests/V1_0/user_subscribe_settings_details.rb
|
122
|
+
- lib/syncwise_api/requests/V1_0/vehicle_gauge_information.rb
|
123
|
+
- lib/syncwise_api/requests/V1_0/vehicle_idling_history.rb
|
124
|
+
- lib/syncwise_api/requests/requests.rb
|
125
|
+
- lib/syncwise_api/responses/V1_0/base.rb
|
126
|
+
- lib/syncwise_api/responses/V1_0/standard.rb
|
127
|
+
- lib/syncwise_api/responses/responses.rb
|
128
|
+
- lib/syncwise_api/service_utils/crypto/hmac_sha256.rb
|
129
|
+
- lib/syncwise_api/service_utils/encoders/base64.rb
|
130
|
+
- lib/syncwise_api/service_utils/encoders/json.rb
|
131
|
+
- lib/syncwise_api/service_utils/http.rb
|
132
|
+
- lib/syncwise_api/service_utils/parsers/json.rb
|
133
|
+
- lib/syncwise_api/service_utils/service_utils.rb
|
134
|
+
- lib/syncwise_api/service_utils/time_stamper.rb
|
135
|
+
- lib/syncwise_api/version.rb
|
136
|
+
- syncwise_api.gemspec
|
137
|
+
- tester.rb
|
138
|
+
homepage: https://bitbucket.org/mavizon/syncwise_api
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.0.0
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Syncwise API library for Ruby
|
162
|
+
test_files: []
|