rlyft 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +4 -0
- data/README.md +60 -34
- data/lib/lyft.rb +7 -10
- data/lib/lyft/client.rb +20 -16
- data/lib/lyft/client/api.rb +8 -0
- data/lib/lyft/client/api/availability.rb +55 -66
- data/lib/lyft/client/api/base.rb +26 -76
- data/lib/lyft/client/api/oauth.rb +15 -37
- data/lib/lyft/client/api/oauth/grant_type.rb +12 -0
- data/lib/lyft/client/api/oauth/scope.rb +18 -0
- data/lib/lyft/client/api/rides.rb +143 -140
- data/lib/lyft/client/api/user.rb +21 -28
- data/lib/lyft/client/configuration.rb +3 -2
- data/lib/lyft/response.rb +8 -0
- data/lib/lyft/version.rb +1 -1
- data/lyft.gemspec +4 -5
- metadata +10 -21
- data/lib/lyft/client/mashed_parser.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1571d70c3a0cb544192c6d344b3bcf31082070b
|
4
|
+
data.tar.gz: 1aa7de7ac5b6506c9461f2122fbcd912f42cec6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff7696a0fe03fd049cda9780597f036c0eb58fa1425e786385fdd983e95f2251c48e9863e2aaedc196316150bb18af874946f2107aa7cc88d42e45bed7948dd
|
7
|
+
data.tar.gz: 623c9b3143eaee11807dee1d2dbef78c8d8e19ee38c2af9926e59e26504e149c283ea73fbfbd4a902b95ec511709700fd60127a77e73a98044cc38f61546a72b
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -8,8 +8,12 @@ AllCops:
|
|
8
8
|
TargetRubyVersion: 2.3
|
9
9
|
Metrics/BlockLength:
|
10
10
|
Enabled: false
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Enabled: false
|
11
13
|
Metrics/LineLength:
|
12
14
|
Enabled: false
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
13
17
|
Style/AccessorMethodName:
|
14
18
|
Enabled: false
|
15
19
|
Style/ClassVars:
|
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# RLyft
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/rlyft.svg)](https://badge.fury.io/rb/rlyft)
|
2
3
|
[![CircleCI](https://circleci.com/gh/skukx/rlyft.svg?style=shield)](https://circleci.com/gh/skukx/rlyft)
|
3
4
|
|
4
5
|
Simple wrapper for interacting with Lyft's public api.
|
5
6
|
|
7
|
+
## Breaking Changes
|
8
|
+
See https://github.com/skukx/rlyft/pull/6
|
9
|
+
|
6
10
|
## Installation
|
7
11
|
|
8
12
|
Add this line to your application's Gemfile:
|
9
13
|
|
10
14
|
```ruby
|
11
|
-
gem '
|
15
|
+
gem 'rlyft', require 'lyft'
|
12
16
|
```
|
13
17
|
|
14
18
|
And then execute:
|
@@ -21,7 +25,6 @@ And then execute:
|
|
21
25
|
client = Lyft::Client.new(
|
22
26
|
client_id: 'client_id',
|
23
27
|
client_secret: 'client_secret',
|
24
|
-
debug_output: STDOUT,
|
25
28
|
use_sandbox: true
|
26
29
|
)
|
27
30
|
```
|
@@ -31,62 +34,74 @@ Get Access Token:
|
|
31
34
|
|
32
35
|
```ruby
|
33
36
|
# Public token
|
34
|
-
client.
|
37
|
+
client.oauth.retrieve_access_token
|
35
38
|
|
36
39
|
# When using oauth.
|
37
|
-
client.
|
40
|
+
client.oauth.retrieve_access_token authorization_code: 'auth_code'
|
38
41
|
```
|
39
42
|
|
40
43
|
Calculate Lyft cost.
|
41
44
|
|
42
45
|
```ruby
|
43
|
-
client.availability.cost access_token: 'access_token'
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
client.availability.cost access_token: 'access_token',
|
47
|
+
params: {
|
48
|
+
start_lat: 37.7772,
|
49
|
+
start_lng: -122.4233,
|
50
|
+
end_lat: 37.7972,
|
51
|
+
end_lng: -122.4533
|
52
|
+
}
|
48
53
|
```
|
49
54
|
|
50
55
|
Time for nearest driver to reach location.
|
51
56
|
|
52
57
|
```ruby
|
53
58
|
client.availability.eta access_token: 'token',
|
54
|
-
|
55
|
-
|
59
|
+
params: {
|
60
|
+
lat: 37.7772,
|
61
|
+
lng: -122.4233
|
62
|
+
}
|
56
63
|
```
|
57
64
|
|
58
65
|
Get the location of nearby drivers.
|
59
66
|
|
60
67
|
```ruby
|
61
68
|
client.availability.nearby_drivers access_token: 'token',
|
62
|
-
|
63
|
-
|
69
|
+
params: {
|
70
|
+
lat: 37.7772,
|
71
|
+
lng: -122.4233
|
72
|
+
}
|
64
73
|
```
|
65
74
|
|
66
75
|
Get available ride types.
|
67
76
|
|
68
77
|
```ruby
|
69
78
|
client.availability.ride_types access_token: 'token',
|
70
|
-
|
71
|
-
|
79
|
+
params: {
|
80
|
+
lat: 37.7772,
|
81
|
+
lng: -122.4233
|
82
|
+
}
|
72
83
|
```
|
73
84
|
|
74
85
|
Request a ride
|
75
86
|
```ruby
|
76
87
|
client.rides.request access_token: 'token',
|
77
|
-
|
78
|
-
|
88
|
+
params: {
|
89
|
+
origin: { lat: 37.7772, lng: -122.4233 },
|
90
|
+
ride_type: Lyft::Ride::Type::LYFT
|
91
|
+
}
|
79
92
|
```
|
80
93
|
|
81
94
|
Cancel a ride
|
82
95
|
```ruby
|
83
96
|
client.rides.cancel access_token: 'token',
|
84
|
-
ride_id: '123'
|
97
|
+
params: { ride_id: '123' }
|
85
98
|
|
86
99
|
# When cancel_confirmation_token is needed.
|
87
100
|
client.rides.cancel access_token: 'token',
|
88
|
-
|
89
|
-
|
101
|
+
params: {
|
102
|
+
ride_id: '123',
|
103
|
+
cancel_confirmation_token: 'cancellation_token'
|
104
|
+
}
|
90
105
|
```
|
91
106
|
|
92
107
|
## Using the Sandbox:
|
@@ -95,9 +110,14 @@ Set available ride types
|
|
95
110
|
```ruby
|
96
111
|
client.rides.set_ridetypes(
|
97
112
|
access_token: 'my_token',
|
98
|
-
|
99
|
-
|
100
|
-
|
113
|
+
params: {
|
114
|
+
lat: 37.7833,
|
115
|
+
lng: -122.4167,
|
116
|
+
ride_types: [
|
117
|
+
Lyft::Ride::Type::LYFT,
|
118
|
+
Lyft::Ride::Type::LYFT_PLUS
|
119
|
+
]
|
120
|
+
}
|
101
121
|
)
|
102
122
|
```
|
103
123
|
|
@@ -105,8 +125,10 @@ Set ride status
|
|
105
125
|
```ruby
|
106
126
|
client.rides.set_status(
|
107
127
|
access_token: 'my_token',
|
108
|
-
|
109
|
-
|
128
|
+
params: {
|
129
|
+
ride_id: 'my_ride_id',
|
130
|
+
status: Lyft::Ride::Status::ACCEPTED
|
131
|
+
}
|
110
132
|
)
|
111
133
|
```
|
112
134
|
|
@@ -114,10 +136,12 @@ Set driver availability
|
|
114
136
|
```ruby
|
115
137
|
client.rides.set_driver_availability(
|
116
138
|
access_token: 'my_token',
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
139
|
+
params: {
|
140
|
+
ride_type: Lyft::Ride::Type::LYFT_SUV
|
141
|
+
lat: 37.7833,
|
142
|
+
lng: -122.4167,
|
143
|
+
driver_availability: true
|
144
|
+
}
|
121
145
|
)
|
122
146
|
```
|
123
147
|
|
@@ -125,9 +149,11 @@ Set primetime percentage
|
|
125
149
|
```ruby
|
126
150
|
client.rides.set_primetime(
|
127
151
|
access_token: 'my_token',
|
128
|
-
|
129
|
-
|
130
|
-
|
152
|
+
params: {
|
153
|
+
lat: 37.7833,
|
154
|
+
lng: -122.4167,
|
155
|
+
primetime_percentage: '25%'
|
156
|
+
}
|
131
157
|
)
|
132
158
|
```
|
133
159
|
|
@@ -139,7 +165,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
139
165
|
|
140
166
|
## Contributing
|
141
167
|
|
142
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
168
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/skukx/lyft.
|
143
169
|
|
144
170
|
|
145
171
|
## License
|
data/lib/lyft.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
# Development gems
|
2
|
-
require 'pry'
|
3
|
-
|
4
1
|
# 3rd party Libraries
|
5
|
-
require 'httparty'
|
6
2
|
require 'active_support/all'
|
7
|
-
require '
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
8
5
|
|
6
|
+
require 'lyft/response'
|
9
7
|
require 'lyft/ride'
|
10
8
|
require 'lyft/version'
|
11
9
|
|
12
|
-
require 'lyft/client/
|
13
|
-
require 'lyft/client/mashed_parser'
|
14
|
-
|
10
|
+
require 'lyft/client/api'
|
15
11
|
require 'lyft/client/api/base'
|
16
12
|
require 'lyft/client/api/availability'
|
17
13
|
require 'lyft/client/api/oauth'
|
14
|
+
require 'lyft/client/api/oauth/grant_type'
|
15
|
+
require 'lyft/client/api/oauth/scope'
|
18
16
|
require 'lyft/client/api/rides'
|
19
17
|
require 'lyft/client/api/user'
|
20
18
|
|
21
19
|
require 'lyft/client'
|
22
|
-
|
23
|
-
module Lyft; end
|
20
|
+
require 'lyft/client/configuration'
|
data/lib/lyft/client.rb
CHANGED
@@ -4,12 +4,17 @@ module Lyft
|
|
4
4
|
#
|
5
5
|
class Client
|
6
6
|
##
|
7
|
-
#
|
7
|
+
# The configuration for the Lyft Client
|
8
|
+
# @return [Lyft::Api::Configuration]
|
8
9
|
#
|
9
|
-
@@namespaces = []
|
10
|
-
|
11
10
|
attr_reader :configuration
|
12
11
|
|
12
|
+
##
|
13
|
+
# Keep track of what we are namespacing.
|
14
|
+
#
|
15
|
+
@namespaces = []
|
16
|
+
@connection = nil
|
17
|
+
|
13
18
|
##
|
14
19
|
# Defines a method to access class instance.
|
15
20
|
#
|
@@ -19,18 +24,7 @@ module Lyft
|
|
19
24
|
def self.namespace(name)
|
20
25
|
converted = name.to_s.split('_').map(&:capitalize).join
|
21
26
|
klass = Lyft::Client::Api.const_get(converted)
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Dynamically creates an attr_reader for each client space
|
27
|
-
# and sets it to the initalized values
|
28
|
-
#
|
29
|
-
def self.create_instance(klass)
|
30
|
-
reader = klass.to_s.split('::').last.underscore
|
31
|
-
@@namespaces << reader
|
32
|
-
|
33
|
-
define_method(reader.to_sym) { klass.new @@config }
|
27
|
+
@namespaces << klass
|
34
28
|
end
|
35
29
|
|
36
30
|
##
|
@@ -67,7 +61,17 @@ module Lyft
|
|
67
61
|
#
|
68
62
|
def initialize(args = {})
|
69
63
|
@configuration = Lyft::Client::Configuration.new args
|
70
|
-
|
64
|
+
build_namespaces
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def build_namespaces
|
70
|
+
namespaces = self.class.instance_variable_get(:@namespaces)
|
71
|
+
namespaces.each do |klass|
|
72
|
+
reader = klass.to_s.split('::').last.underscore
|
73
|
+
self.class.send(:define_method, reader.to_sym) { klass.new @configuration }
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -2,104 +2,93 @@ module Lyft
|
|
2
2
|
class Client
|
3
3
|
module Api
|
4
4
|
class Availability < Lyft::Client::Api::Base
|
5
|
-
ENDPOINTS = {
|
6
|
-
cost: "/#{API_VERSION}/cost",
|
7
|
-
eta: "/#{API_VERSION}/eta",
|
8
|
-
nearby_drivers: "/#{API_VERSION}/drivers",
|
9
|
-
ride_types: "/#{API_VERSION}/ridetypes"
|
10
|
-
}
|
11
|
-
|
12
5
|
##
|
13
6
|
# Get the estimated cost of ride.
|
14
7
|
#
|
15
8
|
# @example Get the estimated cost of a ride.
|
16
9
|
# client.availability.cost(
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
10
|
+
# access_token: 'token',
|
11
|
+
# params: {
|
12
|
+
# start_lat: 37.7772,
|
13
|
+
# start_lng: -122.4233,
|
14
|
+
# end_lat: 37.7972,
|
15
|
+
# end_lng: -122.4533
|
16
|
+
# }
|
22
17
|
# )
|
23
18
|
#
|
24
|
-
# @param [
|
25
|
-
# @
|
26
|
-
# @option
|
27
|
-
# @option
|
28
|
-
# @option
|
29
|
-
# @option
|
19
|
+
# @param access_token [String] The access_token (*required*)
|
20
|
+
# @param params [Hash] The lyft parameters.
|
21
|
+
# @option params [Float] :start_lat The latitude of starting point. (*required*)
|
22
|
+
# @option params [Float] :start_lng The longitude of starting point. (*required*)
|
23
|
+
# @option params [Float] :end_lat The latitude of the end point. (*required*)
|
24
|
+
# @option params [Float] :end_lng The longitude of the end point. (*required*)
|
30
25
|
#
|
31
|
-
def cost(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
)
|
26
|
+
def cost(access_token:, params: {})
|
27
|
+
resp = connection(access_token).get do |req|
|
28
|
+
req.url "/#{Api::VERSION}/cost"
|
29
|
+
req.params = params
|
30
|
+
end
|
31
|
+
handle_response(resp)
|
38
32
|
end
|
39
33
|
|
40
34
|
##
|
41
35
|
# Get eta for lyft driver to reach location
|
42
36
|
#
|
43
37
|
# @example Get lyft eta to a specified location.
|
44
|
-
# client.availability.eta
|
45
|
-
# lng: -122.4233
|
46
|
-
# access_token: 'token'
|
38
|
+
# client.availability.eta access_token: 'my_token',
|
39
|
+
# params: { lat: 37.7772, lng: -122.4233 }
|
47
40
|
#
|
48
|
-
# @param [
|
49
|
-
# @
|
50
|
-
# @option
|
51
|
-
# @option
|
41
|
+
# @param access_token [String] The access_token (*required*)
|
42
|
+
# @param params [Hash] The lyft parameters.
|
43
|
+
# @option params [Float] :lat The latitude of pickup. (*required*)
|
44
|
+
# @option params [Float] :lng The longitude of pickup. (*required*)
|
52
45
|
#
|
53
|
-
def eta(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
)
|
46
|
+
def eta(access_token:, params: {})
|
47
|
+
resp = connection(access_token).get do |req|
|
48
|
+
req.url "/#{Api::VERSION}/eta"
|
49
|
+
req.params = params
|
50
|
+
end
|
51
|
+
handle_response(resp)
|
60
52
|
end
|
61
53
|
|
62
54
|
##
|
63
55
|
# Get positions of nearby drivers
|
64
56
|
#
|
65
57
|
# @example Get location of nearby drivers.
|
66
|
-
# client.availability.nearby_drivers
|
67
|
-
# lng: -122.4233
|
68
|
-
# access_token: 'token'
|
58
|
+
# client.availability.nearby_drivers access_token: 'my_token',
|
59
|
+
# params: { lat: 37.7772, lng: -122.4233 }
|
69
60
|
#
|
70
|
-
# @param [
|
71
|
-
# @
|
72
|
-
# @option
|
73
|
-
# @option
|
61
|
+
# @param access_token [String] The access_token (*required*)
|
62
|
+
# @param params [Hash] The lyft parameters.
|
63
|
+
# @option params [Float] :lat The latitude of pickup. (*required*)
|
64
|
+
# @option params [Float] :lng The longitude of pickup. (*required*)
|
74
65
|
#
|
75
|
-
def nearby_drivers(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
)
|
66
|
+
def nearby_drivers(access_token:, params: {})
|
67
|
+
resp = connection(access_token).get do |req|
|
68
|
+
req.url "/#{Api::VERSION}/drivers"
|
69
|
+
req.params = params
|
70
|
+
end
|
71
|
+
handle_response(resp)
|
82
72
|
end
|
83
73
|
|
84
74
|
##
|
85
75
|
# Get available lyft ride types
|
86
76
|
#
|
87
77
|
# @example Get available ride types for a location.
|
88
|
-
# client.availability.ride_types
|
89
|
-
# lng: -122.4233
|
78
|
+
# client.availability.ride_types access_token: 'my_token',
|
79
|
+
# params: { lat: 37.7772, lng: -122.4233 }
|
90
80
|
#
|
91
|
-
# @param [
|
92
|
-
# @
|
93
|
-
# @option
|
94
|
-
# @option
|
81
|
+
# @param access_token [String] The access_token (*required*)
|
82
|
+
# @param params [Hash] The lyft parameters.
|
83
|
+
# @option params [Float] :lat The latitude of pickup. (*required*)
|
84
|
+
# @option params [Float] :lng The longitude of pickup. (*required*)
|
95
85
|
#
|
96
|
-
def ride_types(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
)
|
86
|
+
def ride_types(access_token:, params: {})
|
87
|
+
resp = connection(access_token).get do |req|
|
88
|
+
req.url "/#{Api::VERSION}/ridetypes"
|
89
|
+
req.params = params
|
90
|
+
end
|
91
|
+
handle_response(resp)
|
103
92
|
end
|
104
93
|
end
|
105
94
|
end
|