uber-estimates 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 941618ea4da01a2b65fe86af6096fb6c4e6704e4
4
+ data.tar.gz: 2708e1e4993dcc0d17884a22cc80e6594f6fa10c
5
+ SHA512:
6
+ metadata.gz: c693625a0af68542bcb8d545e39210e5d1ab1433473d63e7db739f13ddaf5df3745198304345a6e56e98a81c26b87638d23a4ca34f72d6ec0b3ecf85a5e596bb
7
+ data.tar.gz: 9b3140bc7fe7efc76da9073bb116c2ea800533513003acbfb95b098ebe0b3ec41456117157e23c666bb3147e58a47505c242c6b3c2f6d5516fd849cca252bd49
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uber-estimates.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 littleROR
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.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Bogdan
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.
@@ -0,0 +1,118 @@
1
+ # Uber::Estimates
2
+
3
+ Uber Estimates is a small gem that wraps estimate endpoints from Uber API. Using this gem you will be able to get estimates about Uber rides nice and smooth.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'uber-estimates'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install uber-estimates
20
+
21
+ ## Usage
22
+
23
+ ### Gem configuration
24
+ ```ruby
25
+ Uber::Estimates.configure do |config|
26
+ config.server_token = "your server token"
27
+ end
28
+ ```
29
+
30
+ ### Getting price estimates
31
+ To get price estimates you need to provide ```ruby :price ``` as estimations type, start point and end point coordinates, as below. More details at [Uber Docs](https://developer.uber.com/docs/rides/api/v1-estimates-price)
32
+ ```ruby
33
+ Uber::Estimates.get_estimations(:price,
34
+ {start_latitude: 44.427587, start_longitude: 26.0987345,
35
+ end_latitude: 44.4599565, end_longitude: 26.0984328
36
+ }
37
+ )
38
+ ```
39
+ #### Response:
40
+ ```ruby
41
+ #<Uber::Estimates::Response:0x0000000345cce0
42
+ @code=200,
43
+ @data=
44
+ [#<Uber::Estimates::ResponseTypes::Price:0x0000000345b9f8
45
+ @currency_code="RON",
46
+ @display_name="uberX",
47
+ @distance=3.24,
48
+ @duration=840,
49
+ @estimate="RON20-27",
50
+ @high_estimate=27,
51
+ @localized_display_name="uberX",
52
+ @low_estimate=20,
53
+ @product_id="1ca8d691-9f67-4bfb-9c57-cb727b52b7b7",
54
+ @surge_multiplier=2>,
55
+ #<Uber::Estimates::ResponseTypes::Price:0x0000000345b9d0
56
+ @currency_code="RON",
57
+ @display_name="uberSELECT",
58
+ @distance=3.24,
59
+ @duration=840,
60
+ @estimate="RON19-26",
61
+ @high_estimate=26,
62
+ @localized_display_name="uberSELECT",
63
+ @low_estimate=19,
64
+ @product_id="df439009-d1de-4a3c-9ead-9e0e6f0294b9",
65
+ @surge_multiplier=1.5>,
66
+ #<Uber::Estimates::ResponseTypes::Price:0x0000000345b9a8
67
+ @currency_code="RON",
68
+ @display_name="Uber Child Seat",
69
+ @distance=3.24,
70
+ @duration=840,
71
+ @estimate="RON20-24",
72
+ @high_estimate=24,
73
+ @localized_display_name="Uber Child Seat",
74
+ @low_estimate=20,
75
+ @product_id="99e0492a-acc1-412d-b650-48ed7fed9788",
76
+ @surge_multiplier=1.0>]>
77
+ ```
78
+
79
+ ### Getting time estimates
80
+ To get time estimates you need to provide ```ruby :time ``` as estimations type, start point and end point coordinates, or a product_id. More details at [Uber Docs](https://developer.uber.com/docs/rides/api/v1-estimates-time)
81
+ ```ruby
82
+ Uber::Estimates.get_estimations(:time,
83
+ {start_latitude: 44.427587, start_longitude: 26.0987345,
84
+ end_latitude: 44.4599565, end_longitude: 26.0984328
85
+ }
86
+ )
87
+ ```
88
+ or
89
+ ```ruby
90
+ Uber::Estimates.get_estimations(:time,
91
+ {start_latitude: 44.427587, start_longitude: 26.0987345,
92
+ product_id: "99e0492a-acc1-412d-b650-48ed7fed9788"
93
+ }
94
+ )
95
+ ```
96
+ #### Response
97
+ ```ruby
98
+ #<Uber::Estimates::Response:0x00000001cf2730
99
+ @code=200,
100
+ @data=
101
+ [#<Uber::Estimates::ResponseTypes::Time:0x00000001cf1790
102
+ @display_name="uberX",
103
+ @estimate=300,
104
+ @localized_display_name="uberX",
105
+ @product_id="1ca8d691-9f67-4bfb-9c57-cb727b52b7b7">,
106
+ #<Uber::Estimates::ResponseTypes::Time:0x00000001cf1768
107
+ @display_name="uberSELECT",
108
+ @estimate=420,
109
+ @localized_display_name="uberSELECT",
110
+ @product_id="df439009-d1de-4a3c-9ead-9e0e6f0294b9">]>
111
+ ```
112
+ ## Contributing
113
+
114
+ 1. Fork it ( https://github.com/[my-github-username]/uber-estimates/fork )
115
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
116
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
117
+ 4. Push to the branch (`git push origin my-new-feature`)
118
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "uber/estimates"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require "uber/estimates/version"
2
+ require "uber/estimates/configuration"
3
+ require "uber/estimates/type_exception"
4
+ require "uber/estimates/bad_request_exception"
5
+ require "uber/estimates/request"
6
+ require "uber/estimates/response_types/base_response"
7
+ require "uber/estimates/response_types/time"
8
+ require "uber/estimates/response_types/price"
9
+ require "uber/estimates/response"
10
+
11
+ module Uber
12
+ module Estimates
13
+
14
+ TYPES = [:price, :time].freeze
15
+ class << self
16
+ attr_accessor :configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.get_estimations(type, params)
28
+ raise TypeException.new('Type must be :price or :time') unless TYPES.include?(type)
29
+ response = Request.new(type, params).response
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ module Uber
2
+ module Estimates
3
+ class BadRequestException < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Uber
2
+ module Estimates
3
+ class Configuration
4
+ attr_accessor :server_token
5
+
6
+ def initialize
7
+ @server_token = 'DEFAULT_TOKEN'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ require 'rest-client'
2
+ module Uber
3
+ module Estimates
4
+ class Request
5
+ attr_reader :header, :type, :params
6
+ URLS = {time: 'https://api.uber.com/v1/estimates/time', price: 'https://api.uber.com/v1/estimates/price'}.freeze
7
+
8
+ def initialize(type, params)
9
+ @type = type
10
+ @params = params
11
+ @header = {Authorization: %Q[Token #{::Uber::Estimates.configuration.server_token}] }
12
+ end
13
+
14
+ def response
15
+ Response.new(type, raw_response)
16
+ end
17
+
18
+ private
19
+
20
+ def raw_response
21
+ begin
22
+ RestClient::Request.execute(method: :get, url: URLS[type], payload: params, headers: header)
23
+ rescue Exception => e
24
+ raise BadRequestException.new('Something went wrong on request. Please check params')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+ module Uber
3
+ module Estimates
4
+ class Response
5
+ attr_reader :code, :data
6
+
7
+ def initialize(type, raw_response)
8
+ @code = raw_response.code
9
+ if code >= 200 && code < 300
10
+ raw = JSON.parse(raw_response)
11
+ if type == :time
12
+ @data = raw['times'].map{ |raw_hash| ResponseTypes::Time.new(raw_hash) }
13
+ else
14
+ @data = raw['prices'].map{ |raw_hash| ResponseTypes::Price.new(raw_hash) }
15
+ end
16
+ else
17
+ @data = []
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Uber
2
+ module Estimates
3
+ module ResponseTypes
4
+ class BaseResponse
5
+ attr_reader :localized_display_name, :display_name, :product_id
6
+
7
+ def initialize(raw_hash)
8
+ @localized_display_name = raw_hash['localized_display_name']
9
+ @display_name = raw_hash['display_name']
10
+ @product_id = raw_hash['product_id']
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Uber
2
+ module Estimates
3
+ module ResponseTypes
4
+ class Price < BaseResponse
5
+ attr_reader :high_estimate, :low_estimate, :duration, :surge_multiplier, :currency_code, :distance, :estimate
6
+ def initialize(raw_hash)
7
+ super(raw_hash)
8
+ @high_estimate = raw_hash['high_estimate']
9
+ @low_estimate = raw_hash['low_estimate']
10
+ @duration = raw_hash['duration']
11
+ @surge_multiplier = raw_hash['surge_multiplier']
12
+ @currency_code = raw_hash['currency_code']
13
+ @distance = raw_hash['distance']
14
+ @estimate = raw_hash['estimate']
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Uber
2
+ module Estimates
3
+ module ResponseTypes
4
+ class Time < BaseResponse
5
+ attr_reader :estimate
6
+
7
+ def initialize(raw_hash)
8
+ super(raw_hash)
9
+ @estimate = raw_hash['estimate']
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Uber
2
+ module Estimates
3
+ class TypeException < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Uber
2
+ module Estimates
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -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/estimates/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uber-estimates"
8
+ spec.version = Uber::Estimates::VERSION
9
+ spec.authors = ["Bogdan"]
10
+ spec.email = ["bogdan.timofte@hotmail.com"]
11
+
12
+ spec.summary = %q{Small wraper for Uber API estimations endpoints }
13
+ spec.homepage = "http://github.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rest-client'
22
+ spec.add_dependency "activesupport", ">= 4.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "rspec"
28
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uber-estimates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bogdan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.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: 4.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.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - bogdan.timofte@hotmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - lib/uber/estimates.rb
113
+ - lib/uber/estimates/bad_request_exception.rb
114
+ - lib/uber/estimates/configuration.rb
115
+ - lib/uber/estimates/request.rb
116
+ - lib/uber/estimates/response.rb
117
+ - lib/uber/estimates/response_types/base_response.rb
118
+ - lib/uber/estimates/response_types/price.rb
119
+ - lib/uber/estimates/response_types/time.rb
120
+ - lib/uber/estimates/type_exception.rb
121
+ - lib/uber/estimates/version.rb
122
+ - uber-estimates.gemspec
123
+ homepage: http://github.com
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Small wraper for Uber API estimations endpoints
147
+ test_files: []