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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0503db11b90ab5adce78f79a86c849857afb094
4
- data.tar.gz: bbe410d1d2206df8a3d59e2329a23201a9da6ef8
3
+ metadata.gz: d1571d70c3a0cb544192c6d344b3bcf31082070b
4
+ data.tar.gz: 1aa7de7ac5b6506c9461f2122fbcd912f42cec6a
5
5
  SHA512:
6
- metadata.gz: 4287be90d72943fc8fa5afe601c54eb81faf53c232701ef30f31600485afcd13ab4e9d90a65e993c23514e506091d6f203bf7fb8ff55f5d7794d574dbc41e538
7
- data.tar.gz: c3c5d5ecd300568bbb0af195e06a3d6057c5b79e3c9ffa6450d0e40fb50a6f71ac9cc8bfd6b21be4be709cc2b76ae90ba2f847f88e0d237361c3ee040d08c84e
6
+ metadata.gz: 0ff7696a0fe03fd049cda9780597f036c0eb58fa1425e786385fdd983e95f2251c48e9863e2aaedc196316150bb18af874946f2107aa7cc88d42e45bed7948dd
7
+ data.tar.gz: 623c9b3143eaee11807dee1d2dbef78c8d8e19ee38c2af9926e59e26504e149c283ea73fbfbd4a902b95ec511709700fd60127a77e73a98044cc38f61546a72b
data/.gitignore CHANGED
@@ -11,3 +11,6 @@ lyft_setup.rb
11
11
 
12
12
  # Ignore application configuration
13
13
  /config/application.yml
14
+
15
+ # Ignore setup script
16
+ /lyft_setup.rb
@@ -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
- # Lyft
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 'lyft', git: 'git@github.com:skukx/lyft.git'
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.authentication.retrieve_access_token
37
+ client.oauth.retrieve_access_token
35
38
 
36
39
  # When using oauth.
37
- client.authentication.retrieve_access_token authorization_code: 'auth_code'
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
- start_lat: 37.7772,
45
- start_lng: -122.4233,
46
- end_lat: 37.7972,
47
- end_lng: -122.4533
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
- lat: 37.7772,
55
- lng: -122.4233
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
- lat: 37.7772,
63
- lng: -122.4233
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
- lat: 37.7772,
71
- lng: -122.4233
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
- origin: { lat: 37.7772, lng: -122.4233 },
78
- ride_type: 'lyft'
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
- ride_id: '123',
89
- cancel_confirmation_token: 'cancellation_token'
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
- lat: 37.7833,
99
- lng: -122.4167,
100
- ride_types: [Lyft::Ride::Type::LYFT, Lyft::Ride::Type::LYFT_PLUS]
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
- ride_id: 'my_ride_id',
109
- status: Lyft::Ride::Status::ACCEPTED
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
- ride_type: Lyft::Ride::Type::LYFT_SUV
118
- lat: 37.7833,
119
- lng: -122.4167,
120
- driver_availability: true
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
- lat: 37.7833,
129
- lng: -122.4167,
130
- primetime_percentage: '25%'
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/[USERNAME]/lyft.
168
+ Bug reports and pull requests are welcome on GitHub at https://github.com/skukx/lyft.
143
169
 
144
170
 
145
171
  ## License
@@ -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 'hashie'
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/configuration'
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'
@@ -4,12 +4,17 @@ module Lyft
4
4
  #
5
5
  class Client
6
6
  ##
7
- # Keep track of what we are namespacing.
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
- create_instance(klass)
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
- @@config = @configuration
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
@@ -0,0 +1,8 @@
1
+ module Lyft
2
+ class Client
3
+ module Api
4
+ VERSION = ENV['LYFT_API_VERSION'] || 'v1'
5
+ BASE_URL = 'https://api.lyft.com'
6
+ end
7
+ end
8
+ 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
- # start_lat: 37.7772,
18
- # start_lng: -122.4233,
19
- # end_lat: 37.7972,
20
- # end_lng: -122.4533,
21
- # access_token: 'token'
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 [Hash] args
25
- # @option args [String] :access_token (*required*)
26
- # @option args [Float] :start_lat The latitude of starting point. (*required*)
27
- # @option args [Float] :start_lng The longitude of starting point. (*required*)
28
- # @option args [Float] :end_lat The latitude of the end point. (*required*)
29
- # @option args [Float] :end_lng The longitude of the end point. (*required*)
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(args = {})
32
- make_request(
33
- http_method: :get,
34
- endpoint: path_for(:cost),
35
- access_token: args.delete(:access_token),
36
- options: { query: args }
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 lat: 37.7772,
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 [Hash] args
49
- # @option args [String] :access_token (*required*)
50
- # @option args [Float] :lat The latitude of pickup. (*required*)
51
- # @option args [Float] :lng The longitude of pickup. (*required*)
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(args = {})
54
- make_request(
55
- http_method: :get,
56
- endpoint: path_for(:eta),
57
- access_token: args.delete(:access_token),
58
- options: { query: args }
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 lat: 37.7772,
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 [Hash] args
71
- # @option args [String] :access_token (*required*)
72
- # @option args [Float] :lat The latitude of pickup. (*required*)
73
- # @option args [Float] :lng The longitude of pickup. (*required*)
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(args = {})
76
- make_request(
77
- http_method: :get,
78
- endpoint: path_for(:nearby_drivers),
79
- access_token: args.delete(:access_token),
80
- options: { query: args }
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 lat: 37.7772,
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 [Hash] args
92
- # @option args [String] :access_token (*required*)
93
- # @option args [Float] :lat The latitude of pickup. (*required*)
94
- # @option args [Float] :lng The longitude of pickup. (*required*)
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(args = {})
97
- make_request(
98
- http_method: :get,
99
- endpoint: path_for(:nearby_drivers),
100
- access_token: args.delete(:access_token),
101
- options: { query: args }
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