carriots 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +48 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/carriots.gemspec +39 -0
- data/lib/carriots.rb +31 -0
- data/lib/carriots/api_methods.rb +18 -0
- data/lib/carriots/api_methods/options.rb +50 -0
- data/lib/carriots/api_methods/streams_options.rb +46 -0
- data/lib/carriots/client.rb +49 -0
- data/lib/carriots/configurable.rb +85 -0
- data/lib/carriots/connection.rb +31 -0
- data/lib/carriots/default.rb +77 -0
- data/lib/carriots/version.rb +17 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 428ad99d271d14083a2d938ba7d81573ab6e8cfa
|
4
|
+
data.tar.gz: 64fe8a2ff305c04352e3fe955d5678ce79875533
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf0ba4fd6885034cd435ba16f8d54bd80a8535d6eff4eec2c69072737fd59e4884ed6decb80fe6e2f8501e20cabd8bb8c652ff060d907713ea398e2dd5bbcc09
|
7
|
+
data.tar.gz: 58a462d68d983bd8818f5b032d30da7fd2e7bbf8b26a4fa375c34befcf332a0f691db68e47cb17d373811870324209c2001c9e7be46ce9a3bce96e31b4f8b76f
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-03-19 07:35:40 +0100 using RuboCop version 0.37.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
11
|
+
# URISchemes: http, https
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 100
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies within project spaces
|
35
|
+
|
36
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
37
|
+
reported by contacting a project maintainer at gmgp.info@gmail.com. All
|
38
|
+
complaints will be reviewed and investigated and will result in a response that
|
39
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
40
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
41
|
+
incident.
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
44
|
+
version 1.3.0, available at
|
45
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
46
|
+
|
47
|
+
[homepage]: http://contributor-covenant.org
|
48
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Giovanni Messina
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Carriots
|
2
|
+
|
3
|
+
This is a tiny API wrapper of [Carriots](http://www.carriots.com) services
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'carriots'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install carriots
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
API methods are available as module methods (consuming module-level configuration) or as client instance methods.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# Provide authentication credentials
|
27
|
+
Carriots.configure do |c|
|
28
|
+
c.login = 'giovanni'
|
29
|
+
c.write_api_key = 'your_very_very_very_very_very_very_long_key'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Fetch the current streams
|
33
|
+
Carriots.streams
|
34
|
+
```
|
35
|
+
or
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Provide authentication credentials
|
39
|
+
client = Carriots::Client.new(login: 'giovanni', write_api_key: 'YOUR_API_KEY')
|
40
|
+
|
41
|
+
# Fetch the current streams
|
42
|
+
client.streams
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
or if you have ENV['CARRIOTS_WRITE_API_KEY'] and ENV['CARRIOTS_LOGIN']
|
47
|
+
|
48
|
+
|
49
|
+
### Default client value
|
50
|
+
|
51
|
+
You can override default and options value using ENV variable
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
ENV['CARRIOTS_API_ENDPOINT'] || API_ENDPOINT
|
55
|
+
ENV['CARRIOTS_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
|
56
|
+
ENV['CARRIOTS_USER_AGENT'] || USER_AGENT
|
57
|
+
ENV['CARRIOTS_WEB_ENDPOINT'] || WEB_ENDPOINT
|
58
|
+
|
59
|
+
ENV['CARRIOTS_WRITE_API_KEY']
|
60
|
+
ENV['CARRIOTS_LOGIN']
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
### TODO
|
71
|
+
|
72
|
+
* add better test coverage to Options
|
73
|
+
* add others API call over streams/
|
74
|
+
* ....
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gmgp/carriots. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
|
79
|
+
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
84
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'carriots'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require 'irb'
|
14
|
+
# IRB.start
|
data/bin/setup
ADDED
data/carriots.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carriots/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'carriots'
|
8
|
+
spec.version = Carriots::VERSION
|
9
|
+
spec.authors = ['Giovanni Messina']
|
10
|
+
spec.email = ['gmgp.info@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'carriots api wrapper'
|
13
|
+
spec.description = 'carriots api wrapper'
|
14
|
+
spec.homepage = 'http://github.com/gmgp/carriots'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'webmock', '~> 1.24'
|
35
|
+
spec.add_development_dependency 'minitest-reporters', '~>1.1'
|
36
|
+
|
37
|
+
spec.add_dependency 'faraday', '~>0.9'
|
38
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10'
|
39
|
+
end
|
data/lib/carriots.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'carriots/client'
|
2
|
+
require 'carriots/version'
|
3
|
+
|
4
|
+
#
|
5
|
+
#
|
6
|
+
module Carriots
|
7
|
+
class << self
|
8
|
+
include Carriots::Configurable
|
9
|
+
|
10
|
+
def client
|
11
|
+
return @client if defined?(@client) && @client.same_options?(options)
|
12
|
+
@client = Carriots::Client.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def respond_to_missing?(method_name, include_private = false)
|
18
|
+
client.respond_to?(method_name, include_private)
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(method_name, *args, &block)
|
22
|
+
if client.respond_to?(method_name)
|
23
|
+
return client.send(method_name, *args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Carriots.setup
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# api_methods.rb
|
2
|
+
require_relative './api_methods/streams_options'
|
3
|
+
|
4
|
+
module Carriots
|
5
|
+
# Connecction options for {Client}
|
6
|
+
#
|
7
|
+
module ApiMethods
|
8
|
+
def streams(options = {}, *args)
|
9
|
+
build_options = StreamsOptions.new(options).build_options
|
10
|
+
|
11
|
+
get("streams/#{build_options}", *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def stream(device = default_device, *args)
|
15
|
+
get("streams/#{device}", *args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# options.rb
|
2
|
+
|
3
|
+
module Carriots
|
4
|
+
# Connecction options for {Client}
|
5
|
+
#
|
6
|
+
module ApiMethods
|
7
|
+
# general options for Carriots API
|
8
|
+
#
|
9
|
+
class Options
|
10
|
+
attr_accessor :options
|
11
|
+
attr_accessor :build_options
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@raw_options = options
|
15
|
+
@options = []
|
16
|
+
set_options
|
17
|
+
@build_options = opts_montati
|
18
|
+
end
|
19
|
+
|
20
|
+
def raw
|
21
|
+
@raw_options
|
22
|
+
end
|
23
|
+
|
24
|
+
def keys
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_options
|
29
|
+
keys.each { |key| send("param_#{key}", raw[key]) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def opts_montati
|
33
|
+
return '' if @options.empty?
|
34
|
+
|
35
|
+
'?' + @options.join('&')
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def set_param(key, value)
|
41
|
+
@options << "#{key}=#{value}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_time_param(key, value)
|
45
|
+
v = (value.is_a?(Fixnum) ? value : value.to_time.to_i)
|
46
|
+
set_param(key, v)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative './options'
|
2
|
+
# streams_options.rb
|
3
|
+
|
4
|
+
module Carriots
|
5
|
+
# Connecction options for {Client}
|
6
|
+
#
|
7
|
+
module ApiMethods
|
8
|
+
# options for /streams/ carriots API
|
9
|
+
#
|
10
|
+
class StreamsOptions < Options
|
11
|
+
def keys
|
12
|
+
[:device, :_t, :at, :at_to, :at_from, :max, :offset]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def param__t(value = nil)
|
18
|
+
set_param(:_t, value) if value && %w(sta str).include?(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
def param_at(value = nil)
|
22
|
+
set_time_param(:at, value) if value
|
23
|
+
end
|
24
|
+
|
25
|
+
def param_at_to(value = nil)
|
26
|
+
set_time_param(:at_to, value) if value
|
27
|
+
end
|
28
|
+
|
29
|
+
def param_at_from(value = nil)
|
30
|
+
set_time_param(:at_from, value) if value
|
31
|
+
end
|
32
|
+
|
33
|
+
def param_device(value = nil)
|
34
|
+
set_param(:device, value) if value
|
35
|
+
end
|
36
|
+
|
37
|
+
def param_max(value = nil)
|
38
|
+
set_param(:max, value) if value
|
39
|
+
end
|
40
|
+
|
41
|
+
def param_offset(value = nil)
|
42
|
+
set_param(:offset, value) if value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# client.rb
|
2
|
+
require 'carriots/configurable'
|
3
|
+
require 'carriots/connection'
|
4
|
+
require 'carriots/api_methods'
|
5
|
+
|
6
|
+
module Carriots
|
7
|
+
# Client for the Carriot API
|
8
|
+
#
|
9
|
+
# @see https://www.carriots.com/documentation/api
|
10
|
+
class Client
|
11
|
+
include Carriots::Configurable
|
12
|
+
include Carriots::Connection
|
13
|
+
include Carriots::ApiMethods
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
# Use options passed in, but fall back to module defaults
|
17
|
+
Carriots::Configurable.keys.each do |key|
|
18
|
+
instance_variable_set(:"@#{key}", options[key] ||
|
19
|
+
Carriots.instance_variable_get(:"@#{key}"))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Text representation of the client, masking api_keys
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
def inspect
|
27
|
+
inspected = super
|
28
|
+
|
29
|
+
# mask api_keys
|
30
|
+
# inspected = inspected.gsub! @write_api_key, "*******" if @write_api_key
|
31
|
+
# Only show last 4 of token, secret
|
32
|
+
if @write_api_key
|
33
|
+
inspected = inspected.gsub! @write_api_key, revele_last_n_digit(@write_api_key)
|
34
|
+
end
|
35
|
+
|
36
|
+
inspected
|
37
|
+
end
|
38
|
+
|
39
|
+
def default_device
|
40
|
+
"defaultDevice@#{login}.#{login}"
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def revele_last_n_digit(string, n = 5)
|
46
|
+
('*' * (string.size - n)) + string.reverse[0, n].reverse.to_s
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'carriots/default'
|
2
|
+
|
3
|
+
# configurable.rb
|
4
|
+
module Carriots
|
5
|
+
# Configuration options for {Client}, defaulting to values
|
6
|
+
# in {Default}
|
7
|
+
module Configurable
|
8
|
+
# @!attribute api_endpoint
|
9
|
+
# @return [String] Base URL for API requests. default: https://api.carriots.com/
|
10
|
+
# @!attribute default_media_type
|
11
|
+
# @see https://www.carriots.com/documentation/api/rest_api_headers
|
12
|
+
# @return [String] Configure preferred media type (for API versioning, for example)
|
13
|
+
# @!attribute connection_options
|
14
|
+
# @see https://github.com/lostisland/faraday
|
15
|
+
# @return [Hash] Configure connection options for Faraday
|
16
|
+
# @!attribute [w] write_api_key
|
17
|
+
# @return [String] Carriots api key for whit write access
|
18
|
+
# @!attribute user_agent
|
19
|
+
# @return [String] Configure User-Agent header for requests.
|
20
|
+
# @!attribute web_endpoint
|
21
|
+
# @return [String] Base URL for web URLs. default: https://github.com/
|
22
|
+
|
23
|
+
attr_accessor :default_media_type, :connection_options, :user_agent, :login
|
24
|
+
attr_writer :web_endpoint, :api_endpoint, :write_api_key
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# List of configurable keys for {Carriots::Client}
|
28
|
+
# @return [Array] of option keys
|
29
|
+
def keys
|
30
|
+
@keys ||= [
|
31
|
+
:api_endpoint,
|
32
|
+
:connection_options,
|
33
|
+
:default_media_type,
|
34
|
+
:user_agent,
|
35
|
+
:web_endpoint,
|
36
|
+
:login,
|
37
|
+
:write_api_key
|
38
|
+
]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set configuration options using a block
|
43
|
+
def configure
|
44
|
+
yield self
|
45
|
+
end
|
46
|
+
|
47
|
+
# Reset configuration options to default values
|
48
|
+
def reset!
|
49
|
+
Carriots::Configurable.keys.each do |key|
|
50
|
+
instance_variable_set(:"@#{key}", Carriots::Default.options[key])
|
51
|
+
end
|
52
|
+
self
|
53
|
+
end
|
54
|
+
alias setup reset!
|
55
|
+
|
56
|
+
# Compares client options to a Hash of requested options
|
57
|
+
#
|
58
|
+
# @param opts [Hash] Options to compare with current client options
|
59
|
+
# @return [Boolean]
|
60
|
+
def same_options?(opts)
|
61
|
+
opts.hash == options.hash
|
62
|
+
end
|
63
|
+
|
64
|
+
def api_endpoint
|
65
|
+
@api_endpoint.to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
# Base URL for generated web URLs
|
69
|
+
#
|
70
|
+
# @return [String] Default: https://carriots.com/
|
71
|
+
def web_endpoint
|
72
|
+
@web_endpoint.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def write_api_key
|
76
|
+
@write_api_key.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def options
|
82
|
+
Hash[Carriots::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# connection.rb
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Carriots
|
5
|
+
# Connecction options for {Client}
|
6
|
+
#
|
7
|
+
module Connection
|
8
|
+
def connection
|
9
|
+
@connection ||= begin
|
10
|
+
|
11
|
+
conn = Faraday.new(api_endpoint, connection_options) do |b|
|
12
|
+
b.request :json
|
13
|
+
b.response :json, content_type: /\bjson$/
|
14
|
+
b.use FaradayMiddleware::FollowRedirects
|
15
|
+
|
16
|
+
# b.use :instrumentation
|
17
|
+
b.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
conn.headers['carriots.apiKey'] = write_api_key
|
20
|
+
|
21
|
+
conn
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(path, params = nil)
|
26
|
+
connection.get(path) do |request|
|
27
|
+
request.params = params if params
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# default.rb
|
2
|
+
|
3
|
+
module Carriots
|
4
|
+
# Default configuration options for {Client}
|
5
|
+
#
|
6
|
+
module Default
|
7
|
+
# Default API endpoint
|
8
|
+
API_ENDPOINT = 'https://api.carriots.com'.freeze
|
9
|
+
|
10
|
+
# Default User Agent header string
|
11
|
+
USER_AGENT = "Carriots Ruby Gem #{Carriots::VERSION}".freeze
|
12
|
+
|
13
|
+
# Default media type
|
14
|
+
MEDIA_TYPE = 'application/vnd.carriots.v2+json'.freeze
|
15
|
+
|
16
|
+
# Default WEB endpoint
|
17
|
+
WEB_ENDPOINT = 'https://carriots.com'.freeze
|
18
|
+
|
19
|
+
# # In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder
|
20
|
+
# RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
|
21
|
+
|
22
|
+
class << self
|
23
|
+
# Configuration options
|
24
|
+
# @return [Hash]
|
25
|
+
def options
|
26
|
+
Hash[Carriots::Configurable.keys.map { |key| [key, send(key)] }]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Default API endpoint from ENV or {API_ENDPOINT}
|
30
|
+
# @return [String]
|
31
|
+
def api_endpoint
|
32
|
+
ENV['CARRIOTS_API_ENDPOINT'] || API_ENDPOINT
|
33
|
+
end
|
34
|
+
|
35
|
+
# Default options for Faraday::Connection
|
36
|
+
# @return [Hash]
|
37
|
+
def connection_options
|
38
|
+
{
|
39
|
+
headers: {
|
40
|
+
accept: default_media_type,
|
41
|
+
user_agent: user_agent
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Default media type from ENV or {MEDIA_TYPE}
|
47
|
+
# @return [String]
|
48
|
+
def default_media_type
|
49
|
+
ENV['CARRIOTS_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
|
50
|
+
end
|
51
|
+
|
52
|
+
# Default User-Agent header string from ENV or {USER_AGENT}
|
53
|
+
# @return [String]
|
54
|
+
def user_agent
|
55
|
+
ENV['CARRIOTS_USER_AGENT'] || USER_AGENT
|
56
|
+
end
|
57
|
+
|
58
|
+
# Default web endpoint from ENV or {WEB_ENDPOINT}
|
59
|
+
# @return [String]
|
60
|
+
def web_endpoint
|
61
|
+
ENV['CARRIOTS_WEB_ENDPOINT'] || WEB_ENDPOINT
|
62
|
+
end
|
63
|
+
|
64
|
+
# Default write api key from ENV
|
65
|
+
# @return [String]
|
66
|
+
def write_api_key
|
67
|
+
ENV['CARRIOTS_WRITE_API_KEY']
|
68
|
+
end
|
69
|
+
|
70
|
+
# Default login from ENV
|
71
|
+
# @return [String]
|
72
|
+
def login
|
73
|
+
ENV['CARRIOTS_LOGIN']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Carriots
|
2
|
+
# Current major release.
|
3
|
+
# @return [Integer]
|
4
|
+
MAJOR = 0
|
5
|
+
|
6
|
+
# Current minor release.
|
7
|
+
# @return [Integer]
|
8
|
+
MINOR = 0
|
9
|
+
|
10
|
+
# Current patch level.
|
11
|
+
# @return [Integer]
|
12
|
+
PATCH = 2
|
13
|
+
|
14
|
+
# Full release version.
|
15
|
+
# @return [String]
|
16
|
+
VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carriots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Messina
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-22 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.24'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.24'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: faraday_middleware
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.10'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.10'
|
125
|
+
description: carriots api wrapper
|
126
|
+
email:
|
127
|
+
- gmgp.info@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- carriots.gemspec
|
143
|
+
- lib/carriots.rb
|
144
|
+
- lib/carriots/api_methods.rb
|
145
|
+
- lib/carriots/api_methods/options.rb
|
146
|
+
- lib/carriots/api_methods/streams_options.rb
|
147
|
+
- lib/carriots/client.rb
|
148
|
+
- lib/carriots/configurable.rb
|
149
|
+
- lib/carriots/connection.rb
|
150
|
+
- lib/carriots/default.rb
|
151
|
+
- lib/carriots/version.rb
|
152
|
+
homepage: http://github.com/gmgp/carriots
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
allowed_push_host: https://rubygems.org
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.5.1
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: carriots api wrapper
|
177
|
+
test_files: []
|