Class: Traxo::Client
- Inherits:
-
Object
- Object
- Traxo::Client
- Defined in:
- lib/traxo/client.rb,
lib/traxo/endpoints/trips.rb,
lib/traxo/endpoints/member.rb,
lib/traxo/endpoints/accounts.rb,
lib/traxo/endpoints/segments/air.rb
Constant Summary collapse
- API_URL =
"https://api.traxo.com/v2/"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#error_handling ⇒ Object
readonly
Returns the value of attribute error_handling.
-
#response_format ⇒ Object
readonly
Returns the value of attribute response_format.
Instance Method Summary collapse
- #create_air_segment(args) ⇒ Object
- #create_trip(arg) ⇒ Object
- #delete_air_segment(id) ⇒ Object
- #delete_trip(trip_id) ⇒ Object
- #get_account(id) ⇒ Object
- #get_accounts(options = {}) ⇒ Object
- #get_air_segment(id) ⇒ Object
- #get_air_segments(args = {}) ⇒ Object
- #get_current_trip(options = {}) ⇒ Object
- #get_member ⇒ Object
- #get_past_trips(options = {}) ⇒ Object
- #get_stream(args = {}) ⇒ Object
- #get_trip(trip_id, options = {}) ⇒ Object
- #get_trip_oembed(trip_id) ⇒ Object
- #get_trips(options = {}) ⇒ Object
- #get_upcoming_trips(options = {}) ⇒ Object
- #ignore_http_errors! ⇒ Object
-
#initialize(access_token, client_id, client_secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #raise_http_errors! ⇒ Object
- #return_body! ⇒ Object
- #return_body_string! ⇒ Object
- #return_code! ⇒ Object
- #return_false_if_http_errors! ⇒ Object
- #return_headers! ⇒ Object
- #return_headers_string! ⇒ Object
- #return_http_object! ⇒ Object
- #update_air_segment(id, args) ⇒ Object
- #update_trip(trip_id, args) ⇒ Object
Constructor Details
#initialize(access_token, client_id, client_secret, options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/traxo/client.rb', line 9 def initialize(access_token, client_id, client_secret, = {}) @access_token = access_token @client_secret = client_secret @client_id = client_id () end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/traxo/client.rb', line 4 def access_token @access_token end |
#error_handling ⇒ Object (readonly)
Returns the value of attribute error_handling.
5 6 7 |
# File 'lib/traxo/client.rb', line 5 def error_handling @error_handling end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
5 6 7 |
# File 'lib/traxo/client.rb', line 5 def response_format @response_format end |
Instance Method Details
#create_air_segment(args) ⇒ Object
15 16 17 18 19 |
# File 'lib/traxo/endpoints/segments/air.rb', line 15 def create_air_segment(args) url = "#{ API_URL}segments/air" data = (args) post_request_with_token(url, data) end |
#create_trip(arg) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/traxo/endpoints/trips.rb', line 39 def create_trip(arg) data = create_trip_data(arg) create_trip_check_required_params(data) url = "#{ API_URL}trips" post_request_with_token(url, data) end |
#delete_air_segment(id) ⇒ Object
29 30 31 32 |
# File 'lib/traxo/endpoints/segments/air.rb', line 29 def delete_air_segment(id) url = "#{ API_URL}segments/air/#{id}" delete_request_with_token(url) end |
#delete_trip(trip_id) ⇒ Object
55 56 57 58 59 |
# File 'lib/traxo/endpoints/trips.rb', line 55 def delete_trip(trip_id) raise ArgumentError.new('Must provide an integer trip ID') unless trip_id.is_a?(Fixnum) url = "#{ API_URL }trips/#{ trip_id }" delete_request_with_token(url) end |
#get_account(id) ⇒ Object
4 5 6 7 |
# File 'lib/traxo/endpoints/accounts.rb', line 4 def get_account(id) url = "#{ API_URL}accounts/#{id}" get_request_with_token(url) end |
#get_accounts(options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/traxo/endpoints/accounts.rb', line 9 def get_accounts( = {}) data = () url = "#{ API_URL}accounts#{ query_string(data) }" get_request_with_token(url) end |
#get_air_segment(id) ⇒ Object
10 11 12 13 |
# File 'lib/traxo/endpoints/segments/air.rb', line 10 def get_air_segment(id) url = "#{ API_URL}segments/air/#{id}" get_request_with_token(url) end |
#get_air_segments(args = {}) ⇒ Object
4 5 6 7 8 |
# File 'lib/traxo/endpoints/segments/air.rb', line 4 def get_air_segments(args = {}) query = (args) url = "#{API_URL}segments/air#{ query_string(query) }" get_request_with_token(url) end |
#get_current_trip(options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/traxo/endpoints/trips.rb', line 16 def get_current_trip( = {}) data = () url = "#{ API_URL }trips/current#{ query_string(data) }" get_request_with_token(url) end |
#get_member ⇒ Object
4 5 6 7 |
# File 'lib/traxo/endpoints/member.rb', line 4 def get_member url = "#{ API_URL }me" get_request_with_token(url) end |
#get_past_trips(options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/traxo/endpoints/trips.rb', line 28 def get_past_trips( = {}) data = () url = "#{ API_URL }trips/past#{ query_string(data) }" get_request_with_token(url) end |
#get_stream(args = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/traxo/endpoints/member.rb', line 9 def get_stream(args = {}) args.select! { |key| [:offset, :limit, :count].include? key } url = "#{ API_URL }stream#{ query_string(args) }" get_request_with_token(url) end |
#get_trip(trip_id, options = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/traxo/endpoints/trips.rb', line 10 def get_trip(trip_id, = {}) data = () url = "#{ API_URL }trips/#{ trip_id }#{ query_string(data) }" get_request_with_token(url) end |
#get_trip_oembed(trip_id) ⇒ Object
34 35 36 37 |
# File 'lib/traxo/endpoints/trips.rb', line 34 def (trip_id) url = "#{ API_URL }trips/oembed/#{trip_id}" get_request_with_token(url) end |
#get_trips(options = {}) ⇒ Object
4 5 6 7 8 |
# File 'lib/traxo/endpoints/trips.rb', line 4 def get_trips( = {}) data = () url = "#{ API_URL }trips#{ query_string(data) }" get_request_with_token(url) end |
#get_upcoming_trips(options = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/traxo/endpoints/trips.rb', line 22 def get_upcoming_trips( = {}) data = () url = "#{ API_URL }trips/upcoming#{ query_string(data) }" get_request_with_token(url) end |
#ignore_http_errors! ⇒ Object
46 47 48 49 |
# File 'lib/traxo/client.rb', line 46 def ignore_http_errors! @error_handling = :ignore self end |
#raise_http_errors! ⇒ Object
51 52 53 54 |
# File 'lib/traxo/client.rb', line 51 def raise_http_errors! @error_handling = :raise self end |
#return_body! ⇒ Object
16 17 18 19 |
# File 'lib/traxo/client.rb', line 16 def return_body! @response_format = :body self end |
#return_body_string! ⇒ Object
21 22 23 24 |
# File 'lib/traxo/client.rb', line 21 def return_body_string! @response_format = :body_string self end |
#return_code! ⇒ Object
36 37 38 39 |
# File 'lib/traxo/client.rb', line 36 def return_code! @response_format = :code self end |
#return_false_if_http_errors! ⇒ Object
56 57 58 59 |
# File 'lib/traxo/client.rb', line 56 def return_false_if_http_errors! @error_handling = :bool self end |
#return_headers! ⇒ Object
26 27 28 29 |
# File 'lib/traxo/client.rb', line 26 def return_headers! @response_format = :headers self end |
#return_headers_string! ⇒ Object
31 32 33 34 |
# File 'lib/traxo/client.rb', line 31 def return_headers_string! @response_format = :headers_string self end |
#return_http_object! ⇒ Object
41 42 43 44 |
# File 'lib/traxo/client.rb', line 41 def return_http_object! @response_format = :http self end |
#update_air_segment(id, args) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/traxo/endpoints/segments/air.rb', line 21 def update_air_segment(id, args) url = "#{ API_URL}segments/air/#{id}" data = (args, false) data.delete_if { |key, val| !val } # previous datetime filtering is skipped raise ArgumentError.new('Must provide options to update segment') if data.empty? put_request_with_token(url, data) end |
#update_trip(trip_id, args) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/traxo/endpoints/trips.rb', line 46 def update_trip(trip_id, args) raise ArgumentError.new('Must provide an integer trip ID') unless trip_id.is_a?(Fixnum) raise ArgumentError.new('Must provide a Hash of attributes') unless args.is_a? Hash return false if args.empty? data = create_trip_data_from_hash(args) url = "#{ API_URL }trips/#{ trip_id }" put_request_with_token(url, data) end |