london_cab 0.1.1
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/london_cab/api/endpoints/ride.rb +11 -0
- data/lib/london_cab/api/endpoints.rb +9 -0
- data/lib/london_cab/api/error.rb +12 -0
- data/lib/london_cab/client.rb +27 -0
- data/lib/london_cab/config.rb +33 -0
- data/lib/london_cab/faraday/connection.rb +29 -0
- data/lib/london_cab/faraday/request.rb +37 -0
- data/lib/london_cab/faraday/response/raise_error.rb +14 -0
- data/lib/london_cab/logger.rb +14 -0
- data/lib/london_cab/version.rb +3 -0
- data/lib/london_cab.rb +21 -0
- data/london_cab.gemspec +29 -0
- data/london_cab.png +0 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d9e0d267201dedee13c90e915a83be291835d39
|
4
|
+
data.tar.gz: c272bc19d38e2465d78a9b74b621338508c8ea5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7e9e2cb76dd0ef7b9322e3a520aad715317794dce7a1b95de8f6c1cd952d3aaa83e8d2da92315f7ff08bf2c9069faea4b254dbc9d07584dfd5ca8788c3f4027
|
7
|
+
data.tar.gz: 7b748fc18fdbc833f2b657de37d842539d9814a23f4c5a348f8cc089a3252d43d7f0dce222091f1355f5f31ba58e551a448d11c63267582026c12d59c0b731cf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# LondonCab
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/london_cab)
|
4
|
+
[](https://travis-ci.org/RaMin0/london_cab)
|
5
|
+
[](https://codeclimate.com/github/RaMin0/london_cab)
|
6
|
+
|
7
|
+
A Ruby client for the [London Cab](http://65.182.108.16) APIs.
|
8
|
+
|
9
|
+
[](http://65.182.108.16)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'london_cab'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ gem install london_cab
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### API Token
|
34
|
+
To acquire an API token, use the [london_cab-auth](https://github.com/RaMin0/london_cab-auth) gem. Use the same credentials for your corporate London Cab account.
|
35
|
+
|
36
|
+
### Configuration
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
LondonCab.configure do |config|
|
40
|
+
config.token = ENV['LONDON_CAB_API_TOKEN']
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
This sets a global default token. You can also pass a token to the initializer of `LondonCab::Client`.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client = LondonCab::Client.new(token: ENV['LONDON_CAB_API_TOKEN'])
|
48
|
+
```
|
49
|
+
|
50
|
+
The instance token will be used over the global default.
|
51
|
+
|
52
|
+
The following globals settings are supported via `LondonCab.configure`.
|
53
|
+
|
54
|
+
setting | description
|
55
|
+
-------------|------------
|
56
|
+
token | London Cab API token.
|
57
|
+
logger | An optional logger.<br/>**Default:** `Logger.new(STDOUT)` at `Logger::WARN` level.
|
58
|
+
|
59
|
+
### Client
|
60
|
+
|
61
|
+
The London Cab API allows you to build applications that interact with London Cab.
|
62
|
+
|
63
|
+
#### Configuration
|
64
|
+
setting | description
|
65
|
+
-------------|------------
|
66
|
+
endpoint | London Cab endpoint.<br/>**Default:** http://65.182.108.16:3467/api
|
67
|
+
user_agent | User-agent.<br/>**Default:** LondonCab/VERSION.
|
68
|
+
token | **Required.** London Cab API token.
|
69
|
+
logger | **Optional.** `Logger` instance that logs HTTP requests.
|
70
|
+
|
71
|
+
## Documentation
|
72
|
+
|
73
|
+
### Rides
|
74
|
+
You can use the client to make requests related to rides.
|
75
|
+
|
76
|
+
#### Request Rides
|
77
|
+
|
78
|
+
Request rides with `#ride_request`.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
client.ride_request(PickupLong: '31.276942',
|
82
|
+
PickupLat: '29.962696',
|
83
|
+
DropoffLong: '31.330108',
|
84
|
+
DropoffLat: '30.056610')
|
85
|
+
```
|
86
|
+
|
87
|
+
## History
|
88
|
+
|
89
|
+
The structure of this gem is based on [slack-ruby-gem](https://github.com/slack-ruby/slack-ruby-client).
|
90
|
+
|
91
|
+
## Development
|
92
|
+
|
93
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
94
|
+
|
95
|
+
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).
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/RaMin0/london_cab]().
|
100
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'london_cab'
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module LondonCab
|
2
|
+
class Client
|
3
|
+
include Faraday::Connection
|
4
|
+
include Faraday::Request
|
5
|
+
include Api::Endpoints
|
6
|
+
|
7
|
+
attr_accessor(*Config::ATTRIBUTES)
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
LondonCab::Config::ATTRIBUTES.each do |key|
|
11
|
+
send("#{key}=", options[key] || LondonCab.config.send(key))
|
12
|
+
end
|
13
|
+
|
14
|
+
@logger ||= LondonCab::Config.logger || LondonCab::Logger.default
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def configure
|
19
|
+
block_given? ? yield(Config) : Config
|
20
|
+
end
|
21
|
+
|
22
|
+
def config
|
23
|
+
Config
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LondonCab
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
ATTRIBUTES = [
|
6
|
+
:endpoint,
|
7
|
+
:user_agent,
|
8
|
+
:token,
|
9
|
+
:logger
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
attr_accessor(*Config::ATTRIBUTES)
|
13
|
+
|
14
|
+
def reset
|
15
|
+
self.endpoint = 'http://65.182.108.16:3467/api/CorporateAPI'
|
16
|
+
self.user_agent = "LondonCab/#{LondonCab::VERSION}"
|
17
|
+
self.token = nil
|
18
|
+
self.logger = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
reset
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def configure
|
26
|
+
block_given? ? yield(Config) : Config
|
27
|
+
end
|
28
|
+
|
29
|
+
def config
|
30
|
+
Config
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module LondonCab
|
2
|
+
module Faraday
|
3
|
+
module Connection
|
4
|
+
private
|
5
|
+
|
6
|
+
def connection
|
7
|
+
options = {
|
8
|
+
headers: {
|
9
|
+
'Accept' => 'application/json; charset=utf-8',
|
10
|
+
'Content-Type' => 'application/json'
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
options[:headers]['Authorization'] = "Bearer #{token}" if token
|
15
|
+
options[:headers]['User-Agent'] = user_agent if user_agent
|
16
|
+
|
17
|
+
::Faraday::Connection.new(endpoint, options) do |connection|
|
18
|
+
connection.use ::FaradayMiddleware::EncodeJson
|
19
|
+
connection.use ::LondonCab::Faraday::Response::RaiseError
|
20
|
+
connection.use ::FaradayMiddleware::ParseJson
|
21
|
+
connection.use ::Faraday::Response::RaiseError
|
22
|
+
|
23
|
+
connection.response :logger, logger if logger
|
24
|
+
connection.adapter ::Faraday.default_adapter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LondonCab
|
2
|
+
module Faraday
|
3
|
+
module Request
|
4
|
+
def get(path, options = {})
|
5
|
+
request(:get, path, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(path, options = {})
|
9
|
+
request(:post, path, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(path, options = {})
|
13
|
+
request(:put, path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(path, options = {})
|
17
|
+
request(:delete, path, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request(method, path, options)
|
23
|
+
response = connection.send(method) do |request|
|
24
|
+
case method
|
25
|
+
when :get, :delete
|
26
|
+
request.url(path, options)
|
27
|
+
when :post, :put
|
28
|
+
request.path = path
|
29
|
+
request.body = options unless options.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
response.body
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LondonCab
|
2
|
+
module Faraday
|
3
|
+
module Response
|
4
|
+
class RaiseError < ::Faraday::Response::Middleware
|
5
|
+
def on_complete(env)
|
6
|
+
body = env.body
|
7
|
+
return body['Result'] unless body['HasError']
|
8
|
+
|
9
|
+
raise LondonCab::Api::Error.new(body['Messgage'], env.response)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/london_cab.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'byebug'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'london_cab/version'
|
7
|
+
require 'london_cab/logger'
|
8
|
+
require 'london_cab/config'
|
9
|
+
|
10
|
+
# API
|
11
|
+
require 'faraday'
|
12
|
+
require 'faraday_middleware'
|
13
|
+
require 'json'
|
14
|
+
require 'logger'
|
15
|
+
|
16
|
+
require 'london_cab/api/error'
|
17
|
+
require 'london_cab/faraday/response/raise_error'
|
18
|
+
require 'london_cab/faraday/connection'
|
19
|
+
require 'london_cab/faraday/request'
|
20
|
+
require 'london_cab/api/endpoints'
|
21
|
+
require 'london_cab/client'
|
data/london_cab.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'london_cab/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'london_cab'
|
8
|
+
spec.version = LondonCab::VERSION
|
9
|
+
spec.authors = ['Ramy Aboul Naga']
|
10
|
+
spec.email = ['ramy.naga@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'LondonCab Client'
|
13
|
+
spec.homepage = 'https://github.com/RaMin0/london_cab'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split("\n").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'faraday', '>= 0.9'
|
21
|
+
spec.add_dependency 'faraday_middleware'
|
22
|
+
spec.add_dependency 'json'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'byebug', '~> 9.0'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.47.1'
|
29
|
+
end
|
data/london_cab.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: london_cab
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramy Aboul Naga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '9.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '9.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.47.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.47.1
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- ramy.naga@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- lib/london_cab.rb
|
142
|
+
- lib/london_cab/api/endpoints.rb
|
143
|
+
- lib/london_cab/api/endpoints/ride.rb
|
144
|
+
- lib/london_cab/api/error.rb
|
145
|
+
- lib/london_cab/client.rb
|
146
|
+
- lib/london_cab/config.rb
|
147
|
+
- lib/london_cab/faraday/connection.rb
|
148
|
+
- lib/london_cab/faraday/request.rb
|
149
|
+
- lib/london_cab/faraday/response/raise_error.rb
|
150
|
+
- lib/london_cab/logger.rb
|
151
|
+
- lib/london_cab/version.rb
|
152
|
+
- london_cab.gemspec
|
153
|
+
- london_cab.png
|
154
|
+
homepage: https://github.com/RaMin0/london_cab
|
155
|
+
licenses: []
|
156
|
+
metadata: {}
|
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.6.8
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: LondonCab Client
|
177
|
+
test_files: []
|