spot-gps 0.0.1

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
+ SHA1:
3
+ metadata.gz: 4cefc691cf3adc7c13929ac4ad0aad2e03657b7e
4
+ data.tar.gz: 930728e3875f407014521e9f60bdbf3c9305076f
5
+ SHA512:
6
+ metadata.gz: ee497615830b2294640d2752a7d8ca11100ba4f4b0e3fe1eb4d8002610343807fefb3841b3ac799253e28a250aeb5918aa8967149133eed8580714be79336172
7
+ data.tar.gz: 8f01ed30a2fa1e5c73cd911d36ec558266043396b9f0f21ab1021de1364f444af0b41665a53e0997564b480e16c96ba50a978b9d54240e11bb75c6d6b84314a1
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # SPOT GPS
2
+
3
+ A thin wrapper for SPOT's [API](http://www.findmespot.com/en/index.php?cid=1700).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'spot-gps'
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ There are 3 configuration options:
16
+
17
+ ```ruby
18
+ SPOT.configure do |config|
19
+ config.logger = Logger.new(STDOUT)
20
+ config.open_timeout = 30
21
+ config.read_timeout = 80
22
+ end
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ You can make API calls by using an instance of the `API` class:
28
+
29
+ ```ruby
30
+ api = SPOT::API.new(feed_id: 'FEED_GIID', feed_password: 'OPTIONAL_PASSWORD')
31
+ ```
32
+
33
+ ### Resources
34
+
35
+ Currently, the SPOT API only supports a single `messages` resource.
36
+
37
+ #### Messages
38
+
39
+ Messages are communications sent from a SPOT device.
40
+
41
+ ```ruby
42
+ api.applicant.all # => Returns a (paginated) list of all messages for a feed
43
+ api.applicant.latest # => Returns the most recent message for a feed
44
+ ```
45
+
46
+ ### Pagination
47
+
48
+ All resources that support an `all` method also support pagination. By default,
49
+ the first page of 50 records are fetched. To fetch subsequent pages (each of 50
50
+ records), specify a `page`.
51
+
52
+ ```ruby
53
+ api.message.all(page: 2)
54
+ ```
55
+
56
+ ### Filtering
57
+
58
+ The SPOT API supports filtering by date.
59
+
60
+ ```ruby
61
+ api.message.all(start_at: '2014-06-01T00:00:00', end_at: '2015-06-01T00:00:00')
62
+ ```
63
+
64
+ ### Error Handling
65
+
66
+ TODO: Currently the gem will just raise RestClient errors.
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/greysteil/spot-gps/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
@@ -0,0 +1,13 @@
1
+ module SPOT
2
+ class API
3
+ attr_reader :feed_id, :feed_password
4
+
5
+ def initialize(feed_id:, feed_password: nil)
6
+ @api_service = ApiService.new(feed_id: feed_id, feed_password: feed_password)
7
+ end
8
+
9
+ def messages
10
+ @messages ||= Services::Messages.new(@api_service)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ require 'uri'
2
+ require 'base64'
3
+
4
+ module SPOT
5
+ class ApiService
6
+ def initialize(feed_id:, feed_password: nil)
7
+ @feed_id = feed_id
8
+ @feed_password = feed_password
9
+ end
10
+
11
+ # Make a GET request to the SPOT API
12
+ def get(path:, params: {})
13
+ params = params.merge(feedPassword: feed_password) if feed_password
14
+
15
+ uri = URI.join(base_uri, path)
16
+ uri.query = URI.encode_www_form(params) if params.any?
17
+
18
+ request_options = {
19
+ url: uri.to_s,
20
+ method: :get,
21
+ headers: headers,
22
+ open_timeout: SPOT.open_timeout,
23
+ timeout: SPOT.read_timeout
24
+ }
25
+
26
+ response = RestClient::Request.execute(request_options)
27
+
28
+ JSON.parse(response.body.to_s)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :feed_id, :feed_password
34
+
35
+ def base_uri
36
+ URI.join(SPOT.endpoint, feed_id + '/')
37
+ end
38
+
39
+ def headers
40
+ { 'Accept' => "application/json" }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ module SPOT
2
+ module Configuration
3
+ attr_accessor :open_timeout, :read_timeout
4
+
5
+ def self.extended(base)
6
+ base.reset
7
+ end
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ def reset
14
+ self.open_timeout = 30
15
+ self.read_timeout = 80
16
+ RestClient.log = nil
17
+ end
18
+
19
+ def logger=(log)
20
+ if log.respond_to?(:<<)
21
+ RestClient.log = log
22
+ else
23
+ raise "#{log.class} doesn't seem to behave like a logger!"
24
+ end
25
+ end
26
+
27
+ def logger
28
+ RestClient.log ||= NullLogger.new
29
+ end
30
+
31
+ def endpoint
32
+ "https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ module SPOT
2
+ class NullLogger
3
+ def <<(*args)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module SPOT
2
+ module Services
3
+ class Base
4
+ extend Forwardable
5
+
6
+ def initialize(api_service)
7
+ @api_service = api_service
8
+ end
9
+
10
+ def_delegator :@api_service, :get
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module SPOT
2
+ module Services
3
+ class Messages < Base
4
+ def all(page: nil, start_at: nil, end_at: nil)
5
+ query_params = {}
6
+ query_params[:start] = start(page) if page
7
+ query_params[:startDate] = spot_formatted_time(start_at) if start_at
8
+ query_params[:endDate] = spot_formatted_time(end_at) if end_at
9
+
10
+ get(path: "message.json", params: query_params)
11
+ end
12
+
13
+ def latest
14
+ get(path: "latest.json")
15
+ end
16
+
17
+ private
18
+
19
+ def spot_formatted_time(time)
20
+ return nil unless time
21
+ time = Time.parse(time) if time.is_a?(String)
22
+ time = time.to_time if time.is_a?(Date) || time.is_a?(DateTime)
23
+
24
+ time.gmtime.strftime('%FT%T') + "-0000"
25
+ end
26
+
27
+ def start(page)
28
+ return nil unless page
29
+ raise ArgumentError, "page must be an integer" unless page.is_a?(Integer)
30
+ raise ArgumentError, "page must be non-negative" if page < 0
31
+
32
+ # SPOT start param is zero-indexed
33
+ (page - 1) * 50
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module SPOT
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/spot.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ require 'spot-gps/version'
5
+ require 'spot-gps/configuration'
6
+ require 'spot-gps/null_logger'
7
+ require 'spot-gps/api'
8
+ require 'spot-gps/api_service'
9
+ require 'spot-gps/services/base'
10
+ require 'spot-gps/services/messages'
11
+
12
+ module SPOT
13
+ extend Configuration
14
+ end
data/spot-gps.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spot-gps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'spot-gps'
8
+ spec.version = SPOT::VERSION
9
+ spec.authors = ['Grey Baker']
10
+ spec.email = ['greysteil@gmail.com']
11
+ spec.summary = %q{A wrapper for the SPOT API}
12
+ spec.description = %q{A wrapper for the SPOT API}
13
+ spec.homepage = 'http://github.com/greysteil/spot-gps'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'webmock', '~> 1.22'
24
+ spec.add_development_dependency 'rubocop', '~> 0.37.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.1'
26
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
27
+ spec.add_development_dependency 'sinatra', '~> 1.4'
28
+
29
+ spec.add_dependency 'rest-client', '~> 1.8.0'
30
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spot-gps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Grey Baker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.22'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.22'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.37.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.37.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.8.0
125
+ description: A wrapper for the SPOT API
126
+ email:
127
+ - greysteil@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - README.md
135
+ - lib/spot-gps/api.rb
136
+ - lib/spot-gps/api_service.rb
137
+ - lib/spot-gps/configuration.rb
138
+ - lib/spot-gps/null_logger.rb
139
+ - lib/spot-gps/services/base.rb
140
+ - lib/spot-gps/services/messages.rb
141
+ - lib/spot-gps/version.rb
142
+ - lib/spot.rb
143
+ - spot-gps.gemspec
144
+ homepage: http://github.com/greysteil/spot-gps
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.5.1
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: A wrapper for the SPOT API
168
+ test_files: []