ubercar 0.2

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: ce5062e1b7b89b4cf8e4d2b25681a42a0da749ab
4
+ data.tar.gz: 5cf04a49e4ce4d28621564194be621481ae7d97c
5
+ SHA512:
6
+ metadata.gz: 4024f0b6fd70af44088eef8acde4af06c4cf6400574c75df8e1bc9695cbfce88800d32fb14359b59f1de25ee86b187b37bf8ecb0256424256a176ac01907e9df
7
+ data.tar.gz: def666eb841d448efaec3a1e235f246d6a1162a32309ecb754b3f2991ee13432f2f552e5ef994ad6eb0ff430942d31c74fbc31f58436c118ffeba7f2cf4f74e6
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ sample-client.rb
2
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Lukasz Raczylo
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # Gem for Uber API ( uber.com )
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ubercars.svg)](http://badge.fury.io/rb/ubercars)
4
+ [![Code Climate](https://codeclimate.com/github/lukaszraczylo/uber-ruby/badges/gpa.svg)](https://codeclimate.com/github/lukaszraczylo/uber-ruby)
5
+ [![Gratipay](https://img.shields.io/gratipay/lukaszraczylo.svg)](https://gratipay.com/lukaszraczylo/)
6
+
7
+ This is a Ruby Gem for the uber.com API. It should simplify the process of consuming data from the Uber API for developers using Ruby.
8
+
9
+ ### Installation
10
+ Add following to your application Gemfile
11
+
12
+ ```
13
+ gem 'ubercars'
14
+ ```
15
+
16
+ Then execute
17
+
18
+ ```
19
+ $ bundle install
20
+ ```
21
+
22
+ Or install it just like that
23
+
24
+ ```
25
+ $ gem install ubercars
26
+ ```
27
+
28
+ ### Usage
29
+
30
+ It's pretty straightforward. Sample script using UberCars API:
31
+
32
+ ```
33
+ {
34
+ "products" => [
35
+ [0] {
36
+ "capacity" => 4,
37
+ "image" => "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-uberx.png",
38
+ "display_name" => "uberX",
39
+ "product_id" => "3cb90303-3869-4701-a8fd-92efba468a94",
40
+ "description" => "Cheap, fast & reliable"
41
+ },
42
+ [1] {
43
+ "capacity" => 6,
44
+ "image" => "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-uberXL_london.png",
45
+ "display_name" => "uberXL",
46
+ "product_id" => "d9b19d17-f013-4b98-9b3f-cf5a9e91d2aa",
47
+ "description" => "Spacious, Convenient Comfort"
48
+ },
49
+ [2] {
50
+ "capacity" => 4,
51
+ "image" => "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-black.png",
52
+ "display_name" => "UberEXEC",
53
+ "product_id" => "34a6cad0-0629-4ca0-ae68-ed0cea7695ca",
54
+ "description" => "Discreet executive quality"
55
+ },
56
+ [3] {
57
+ "capacity" => 4,
58
+ "image" => "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-lux.png",
59
+ "display_name" => "UberLUX",
60
+ "product_id" => "ea52c793-1ad7-4c46-96b3-b1836b8cd0f9",
61
+ "description" => "Ultimate luxury & style"
62
+ },
63
+ [4] {
64
+ "capacity" => 5,
65
+ "image" => "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-blacktaxi2.png",
66
+ "display_name" => "UberTAXI",
67
+ "product_id" => "6a6629df-3400-4e4b-8742-ebd79bf4ef99",
68
+ "description" => "Iconic, Knowledgeable & Versatile"
69
+ }
70
+ ]
71
+ }
72
+ {
73
+ "prices" => [
74
+ [0] {
75
+ "localized_display_name" => "uberX",
76
+ "duration" => 393,
77
+ "low_estimate" => "5",
78
+ "display_name" => "uberX",
79
+ "product_id" => "3cb90303-3869-4701-a8fd-92efba468a94",
80
+ "distance" => 1.44,
81
+ "surge_multiplier" => 1.0,
82
+ "estimate" => "£5-6",
83
+ "high_estimate" => "6",
84
+ "currency_code" => "GBP"
85
+ },
86
+ [1] {
87
+ "localized_display_name" => "uberXL",
88
+ "duration" => 393,
89
+ "low_estimate" => "7",
90
+ "display_name" => "uberXL",
91
+ "product_id" => "d9b19d17-f013-4b98-9b3f-cf5a9e91d2aa",
92
+ "distance" => 1.44,
93
+ "surge_multiplier" => 1.0,
94
+ "estimate" => "£7-9",
95
+ "high_estimate" => "9",
96
+ "currency_code" => "GBP"
97
+ },
98
+ [2] {
99
+ "localized_display_name" => "UberEXEC",
100
+ "duration" => 393,
101
+ "low_estimate" => "10",
102
+ "display_name" => "UberEXEC",
103
+ "product_id" => "34a6cad0-0629-4ca0-ae68-ed0cea7695ca",
104
+ "distance" => 1.44,
105
+ "surge_multiplier" => 1.0,
106
+ "estimate" => "£10",
107
+ "high_estimate" => "10",
108
+ "currency_code" => "GBP"
109
+ },
110
+ [3] {
111
+ "localized_display_name" => "UberLUX",
112
+ "duration" => 393,
113
+ "low_estimate" => "14",
114
+ "display_name" => "UberLUX",
115
+ "product_id" => "ea52c793-1ad7-4c46-96b3-b1836b8cd0f9",
116
+ "distance" => 1.44,
117
+ "surge_multiplier" => 1.0,
118
+ "estimate" => "£14",
119
+ "high_estimate" => "14",
120
+ "currency_code" => "GBP"
121
+ },
122
+ [4] {
123
+ "localized_display_name" => "UberTAXI",
124
+ "duration" => 393,
125
+ "low_estimate" => nil,
126
+ "display_name" => "UberTAXI",
127
+ "product_id" => "6a6629df-3400-4e4b-8742-ebd79bf4ef99",
128
+ "distance" => 1.44,
129
+ "surge_multiplier" => 1.0,
130
+ "estimate" => "Metered",
131
+ "high_estimate" => nil,
132
+ "currency_code" => nil
133
+ }
134
+ ]
135
+ }
136
+ {
137
+ "times" => [
138
+ [0] {
139
+ "localized_display_name" => "uberX",
140
+ "estimate" => 508,
141
+ "display_name" => "uberX",
142
+ "product_id" => "3cb90303-3869-4701-a8fd-92efba468a94"
143
+ },
144
+ [1] {
145
+ "localized_display_name" => "UberEXEC",
146
+ "estimate" => 381,
147
+ "display_name" => "UberEXEC",
148
+ "product_id" => "34a6cad0-0629-4ca0-ae68-ed0cea7695ca"
149
+ },
150
+ [2] {
151
+ "localized_display_name" => "UberLUX",
152
+ "estimate" => 576,
153
+ "display_name" => "UberLUX",
154
+ "product_id" => "ea52c793-1ad7-4c46-96b3-b1836b8cd0f9"
155
+ }
156
+ ]
157
+ }
158
+ {
159
+ "display_text" => "£10 account credit",
160
+ "localized_value" => "£10",
161
+ "type" => "account_credit"
162
+ }
163
+ "https://m.uber.com/sign-up?client_id=bananaPotatoKey&"
164
+ ```
data/example-client.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # Sample client for Uber API gem
3
+
4
+ require 'uber'
5
+ require 'ap'
6
+
7
+ CFG_CLIENT_ID = '-banana'
8
+ CFG_SERVER_TOKEN = 'z1FXM8272irpotatO'
9
+ CFG_SECRET = 'B6fzcg4WminionsehnPUr075'
10
+
11
+
12
+ client = UberCar::Client.new({ app_user_key: CFG_CLIENT_ID, app_user_secret: CFG_SECRET, app_server_token: CFG_SERVER_TOKEN, api_host: 'https://api.uber.com/v1' })
13
+
14
+ result = client.show_products(:latitude => '51.512555', :longitude => '-0.127716')
15
+ ap result
16
+
17
+ result = client.estimate_price(:start_latitude => '51.5107835', :start_longitude => '-0.1167915', :end_latitude => '51.5024782', :end_longitude => '-0.1003484')
18
+ ap result
19
+
20
+ result = client.estimate_time(:start_latitude => '51.512555', :start_longitude => '-0.127716')
21
+ # estimate_time can be used with :customer_uuid and product_id for further customization
22
+ ap result
23
+
24
+ result = client.promotions(:start_latitude => '51.5107835', :start_longitude => '-0.1167915', :end_latitude => '51.5024782', :end_longitude => '-0.1003484')
25
+ ap result
26
+
27
+ # returns sign up URL. You can fill up all the fields ( check Uber API documentation )
28
+ result = client.sign_up()
29
+ ap result
data/lib/uber.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'uber/version'
2
+ require 'uber/client'
3
+
4
+ module UberCar
5
+ def self.client
6
+ @client ||= UberCar::Client.new
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ require 'uber/configuration'
2
+ require 'awesome_print'
3
+ require 'httparty'
4
+
5
+ require 'uber/operations/action'
6
+
7
+ module UberCar
8
+ class Client
9
+ REQUEST_CLASSES =[ UberCar::Operations::Action ]
10
+
11
+ attr_reader :configuration
12
+ attr_accessor :session
13
+
14
+ def initialize(options = nil)
15
+ @configuration = nil
16
+ define_request_methods
17
+
18
+ unless options.nil?
19
+ @configuration = Configuration.new(options)
20
+ check_api_keys
21
+ end
22
+ end
23
+
24
+ def check_api_keys
25
+ if configuration.nil? || !configuration.valid?
26
+ @configuration = nil
27
+ raise Error::NoApiKeys
28
+ else
29
+ @configuration.freeze
30
+ end
31
+ end
32
+
33
+ def define_request_methods
34
+ REQUEST_CLASSES.each do |request_class|
35
+ operations_instance = request_class.new(self)
36
+ create_methods_from_instance(operations_instance)
37
+ end
38
+ end
39
+
40
+ def create_methods_from_instance(instance)
41
+ instance.public_methods(false).each do |method_name|
42
+ add_method(instance, method_name)
43
+ end
44
+ end
45
+
46
+ def add_method(instance, method_name)
47
+ define_singleton_method(method_name) do |*args|
48
+ instance.public_send(method_name, *args)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ module UberCar
2
+ class Configuration
3
+ AUTH_KEYS = [:app_user_key, :app_user_secret, :app_server_token, :api_host]
4
+ attr_accessor *AUTH_KEYS
5
+
6
+ def initialize(config_hash = nil)
7
+ if config_hash.is_a?(Hash)
8
+ config_hash.each do |config_name, config_value|
9
+ self.send("#{config_name}=", config_value)
10
+ end
11
+ end
12
+ end
13
+
14
+ # Returns a hash of api keys and their values
15
+ def auth_keys
16
+ AUTH_KEYS.inject({}) do |keys_hash, key|
17
+ keys_hash[key] = send(key)
18
+ keys_hash
19
+ end
20
+ end
21
+
22
+ def valid?
23
+ AUTH_KEYS.none? { |key| send(key).nil? || send(key).empty? }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ require 'addressable/uri'
2
+ require 'open-uri'
3
+ require 'hashie'
4
+ require 'json'
5
+
6
+ module UberCar
7
+ module Operations
8
+ class Action
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def show_products( p = {} )
14
+ param = { :api_url => "/products" }
15
+ param = param.merge(p)
16
+ @client.session = login_request(param)
17
+ end
18
+
19
+ def estimate_price( p = {} )
20
+ param = { :api_url => "/estimates/price" }
21
+ param = param.merge(p)
22
+ @client.session = login_request(param)
23
+ end
24
+
25
+ def estimate_time( p = {} )
26
+ param = { :api_url => "/estimates/time" }
27
+ param = param.merge(p)
28
+ @client.session = login_request(param)
29
+ end
30
+
31
+ def promotions ( p = {} )
32
+ param = { :api_url => "/promotions" }
33
+ param = param.merge(p)
34
+ @client.session = login_request(param)
35
+ end
36
+
37
+ def sign_up ( p = {} )
38
+ q_url = "https://m.uber.com/sign-up?client_id=#{@client.configuration.app_user_key}"
39
+ uri = Addressable::URI.new
40
+ uri.query_values = p
41
+ return "#{q_url}&#{uri.query}"
42
+ end
43
+
44
+ private
45
+ def login_request( p = {} )
46
+ # ap @client.configuration.app_user_key
47
+ if p[:api_url].nil?; p[:api_url] = ''; end
48
+ q_headers = { "Authorization" => "Token #{@client.configuration.app_server_token}" }
49
+ q_request = Hash.new
50
+ q_url = "#{@client.configuration.api_host}#{p[:api_url]}"
51
+ p.delete(:api_url)
52
+ q_request = p
53
+ @options = { :query => q_request, :headers => q_headers }
54
+ obj = HTTParty.get(q_url.to_s, @options).to_json
55
+ result = JSON.parse(obj)
56
+ obj = Hashie::Mash.new(result)
57
+ return obj
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module UberCar
2
+ VERSION = "0.2"
3
+ end
data/uber.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uber/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ubercar'
8
+ spec.version = UberCar::VERSION
9
+ spec.authors = ['Lukasz Raczylo']
10
+ spec.email = ['lukasz@raczylo.com']
11
+ spec.summary = %q{Ruby client library for Uber API}
12
+ spec.description = 'Provides easy way to interact with the Uber API in any kind of application'
13
+ spec.homepage = 'https://github.com/lukaszraczylo/uber-ruby'
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
+ # Requirements
22
+ spec.required_ruby_version = '>=1.9.2'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
25
+ spec.add_development_dependency 'rspec', '~> 2.6'
26
+ spec.add_development_dependency 'hashie', '~> 3.3', '>= 3.3.1'
27
+ spec.add_development_dependency 'addressable', '~> 2.3', '>= 2.3.5'
28
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ubercar
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Lukasz Raczylo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.0.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: hashie
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.3'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.3.1
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '3.3'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.3.1
81
+ - !ruby/object:Gem::Dependency
82
+ name: addressable
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.3'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.3.5
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.3'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.5
101
+ description: Provides easy way to interact with the Uber API in any kind of application
102
+ email:
103
+ - lukasz@raczylo.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - LICENSE
110
+ - README.md
111
+ - example-client.rb
112
+ - lib/uber.rb
113
+ - lib/uber/client.rb
114
+ - lib/uber/configuration.rb
115
+ - lib/uber/operations/action.rb
116
+ - lib/uber/version.rb
117
+ - uber.gemspec
118
+ homepage: https://github.com/lukaszraczylo/uber-ruby
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.9.2
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Ruby client library for Uber API
142
+ test_files: []