Module: BlablaClient
- Defined in:
- lib/blabla_client.rb,
lib/blabla_client/version.rb
Constant Summary collapse
- CURRENT_TOKEN =
Note : token expiration is ignored for now (current token expires on 15/03/2015)
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0MjY0MjY5NTUsImNsaWVudCI6ImE3NzM3ODdhNmI2YjM0NzlhMjk5NTg0MDUwMmUwNDZkNGE0NDNjYmE2MDFjMDk2Y2U1NGI4OTcyYjRkZTdjNzkiLCJzY29wZSI6IiIsInVzZXIiOm51bGx9.dOZF0wbZtW6_Vfa5dU6_X831yGCJlsSZE7gkdp2lldg'- VERSION =
"0.0.1"
Class Method Summary collapse
- .available_trips(departure, arrival, date_range_start, date_range_end, page = 1) ⇒ Object
- .config ⇒ Object
-
.configure(opts = {}) ⇒ Object
Configure through hash.
- .normalize_date(date) ⇒ Object
Class Method Details
.available_trips(departure, arrival, date_range_start, date_range_end, page = 1) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/blabla_client.rb', line 35 def self.available_trips(departure, arrival, date_range_start, date_range_end, page = 1) trips = [] range_start = normalize_date(date_range_start) range_end = normalize_date(date_range_end) begin response = get_response(departure, arrival, range_start, range_end, page) trips = Trip.parse_response(response.body) @logger.info("Retrieved #{trips[:trips].length} trips for page #{page} of request #{departure}-#{arrival} from #{range_start} to #{range_end}") rescue OAuth2::Error => e @logger.error("An error occurred while calling the API on #{@config[:api_url]}") @logger.error("Response : #{e.response}") @logger.error("Code : #{e.code}") @logger.error("Description : #{e.description}") end trips end |
.config ⇒ Object
31 32 33 |
# File 'lib/blabla_client.rb', line 31 def self.config @config end |
.configure(opts = {}) ⇒ Object
Configure through hash
27 28 29 |
# File 'lib/blabla_client.rb', line 27 def self.configure(opts = {}) opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym} end |
.normalize_date(date) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/blabla_client.rb', line 52 def self.normalize_date(date) if date.is_a?(Date) || date.is_a?(DateTime) || date.is_a?(Time) date_as_object = date else date_as_object = Date.parse(date) end date_as_object.strftime('%d-%m-%Y') end |