Class: FlightStats::API
- Inherits:
-
Object
show all
- Extended by:
- Net::HTTPAdapter
- Defined in:
- lib/flightstats/api.rb,
lib/flightstats/api/errors.rb,
lib/flightstats/api/net_http_adapter.rb
Defined Under Namespace
Modules: Net
Classes: BadRequest, ClientError, Forbidden, InternalServerError, MethodNotAllowed, NotFound, Redirection, ResponseError, ServerError
Constant Summary
collapse
- ERRORS =
Error mapping by status code.
Hash.new { |hash, code|
unless hash.key? code
case code
when 400...500 then ClientError
when 500...600 then ServerError
else ResponseError
end
end
}.update(
400 => BadRequest,
403 => Forbidden,
404 => NotFound,
405 => MethodNotAllowed,
500 => InternalServerError
).freeze
- @@base_uri =
"https://api.flightstats.com"
Instance Attribute Summary
#net_http
Class Method Summary
collapse
-
.accept_language ⇒ String?
Accept-Language header value.
-
.accept_language=(language) ⇒ Object
-
.base_uri ⇒ URI::Generic
-
.delete(uri, options = {}) ⇒ Net::HTTPNoContent, Net::HTTPResponse
-
.get(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.head(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.headers ⇒ Hash{String => String}
Additional HTTP headers sent with each API call.
-
.post(uri, body = nil, options = {}) ⇒ Net::HTTPCreated, Net::HTTPResponse
-
.put(uri, body = nil, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.user_agent ⇒ String
Class Method Details
.accept_language ⇒ String?
Returns Accept-Language header value.
16
17
18
|
# File 'lib/flightstats/api.rb', line 16
def accept_language
['Accept-Language']
end
|
.accept_language=(language) ⇒ Object
21
22
23
|
# File 'lib/flightstats/api.rb', line 21
def accept_language=(language)
['Accept-Language'] = language
end
|
.base_uri ⇒ URI::Generic
56
57
58
|
# File 'lib/flightstats/api.rb', line 56
def base_uri
URI.parse @@base_uri
end
|
.delete(uri, options = {}) ⇒ Net::HTTPNoContent, Net::HTTPResponse
51
52
53
|
# File 'lib/flightstats/api.rb', line 51
def delete uri, options = {}
request :delete, uri, options
end
|
.get(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
33
34
35
|
# File 'lib/flightstats/api.rb', line 33
def get uri, params = {}, options = {}
request :get, uri, { :params => params }.merge(options)
end
|
.head(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
27
28
29
|
# File 'lib/flightstats/api.rb', line 27
def head uri, params = {}, options = {}
request :head, uri, { :params => params }.merge(options)
end
|
Additional HTTP headers sent with each API call
11
12
13
|
# File 'lib/flightstats/api.rb', line 11
def
@headers ||= { 'Accept' => accept, 'User-Agent' => user_agent }
end
|
.post(uri, body = nil, options = {}) ⇒ Net::HTTPCreated, Net::HTTPResponse
39
40
41
|
# File 'lib/flightstats/api.rb', line 39
def post uri, body = nil, options = {}
request :post, uri, { :body => body.to_s }.merge(options)
end
|
.put(uri, body = nil, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
45
46
47
|
# File 'lib/flightstats/api.rb', line 45
def put uri, body = nil, options = {}
request :put, uri, { :body => body.to_s }.merge(options)
end
|
.user_agent ⇒ String
61
62
63
|
# File 'lib/flightstats/api.rb', line 61
def user_agent
"FlightStats/#{FlightStats::Version}; #{RUBY_DESCRIPTION}"
end
|