Class: Streambird::Api
- Inherits:
-
Struct
- Object
- Struct
- Streambird::Api
show all
- Defined in:
- lib/streambird/api.rb,
lib/streambird/api/otp.rb,
lib/streambird/api/user.rb,
lib/streambird/api/oauth.rb,
lib/streambird/api/errors.rb,
lib/streambird/api/wallet.rb,
lib/streambird/api/session.rb,
lib/streambird/api/magic_link.rb,
lib/streambird/api/oauth_connection.rb
Defined Under Namespace
Classes: APIKeyInvalid, BadRequest, ConnectionError, Error, InternalServerError, MagicLink, NotFound, OAuth, OAuthConnection, Otp, Session, TooManyRequests, Unauthorized, User, Wallet
Constant Summary
collapse
- STREAMBIRD_API_URL =
ENV['STREAMBIRD_API_URL'] || 'https://api.streambird.io/v1/'
- STREAMBIRD_GEM_INFO =
Gem.loaded_specs["streambird"]
- STREAMBIRD_RUBY_CLIENT_VERSION =
STREAMBIRD_GEM_INFO ? STREAMBIRD_GEM_INFO.version.to_s : '0.1.1'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key
6
7
8
|
# File 'lib/streambird/api.rb', line 6
def api_key
@api_key
end
|
#default_request_params ⇒ Object
Returns the value of attribute default_request_params
6
7
8
|
# File 'lib/streambird/api.rb', line 6
def default_request_params
@default_request_params
end
|
#logging ⇒ Object
Returns the value of attribute logging
6
7
8
|
# File 'lib/streambird/api.rb', line 6
def logging
@logging
end
|
Instance Method Details
#connection ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/streambird/api.rb', line 11
def connection
@connection ||= Faraday.new(:url => STREAMBIRD_API_URL) do |faraday|
faraday.request :authorization, 'Bearer', self.api_key
faraday.request :url_encoded faraday.response :logger if logging faraday.adapter Faraday.default_adapter end
end
|
#delete(url, body = {}) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/streambird/api.rb', line 76
def delete(url, body = {})
body = default_request_params.merge(body)
response = connection.delete do |req|
req.url "#{STREAMBIRD_API_URL}#{url}"
req.['Content-Type'] = 'application/json'
req.body = body.to_json
req.['X-API-Client'] = "Ruby"
req.["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
end
if response.status != 200 and response.status != 201
return handle_error(response)
end
response
rescue Faraday::Error::ConnectionFailed
raise Streambird::Api::ConnectionError
end
|
#get(url, params = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/streambird/api.rb', line 20
def get(url, params = {})
response = connection.get do |req|
req.url "#{STREAMBIRD_API_URL}#{url}"
req.params.merge!(default_request_params.merge(params))
req.['X-API-Client'] = "Ruby"
req.["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
end
if response.status != 200
return handle_error(response)
end
response
rescue Faraday::Error::ConnectionFailed
raise Streambird::Api::ConnectionError
end
|
#handle_error(response) ⇒ Object
#post(url, body = {}) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/streambird/api.rb', line 37
def post(url, body = {})
body = default_request_params.merge(body)
response = connection.post do |req|
req.url "#{STREAMBIRD_API_URL}#{url}"
req.['Content-Type'] = 'application/json'
req.body = body.to_json
req.['X-API-Client'] = "Ruby"
req.["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
end
if response.status != 200 and response.status != 201
return handle_error(response)
end
response
rescue Faraday::Error::ConnectionFailed
raise Streambird::Api::ConnectionError
end
|
#put(url, body = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/streambird/api.rb', line 56
def put(url, body = {})
body = default_request_params.merge(body)
response = connection.put do |req|
req.url "#{STREAMBIRD_API_URL}#{url}"
req.['Content-Type'] = 'application/json'
req.body = body.to_json
req.['X-API-Client'] = "Ruby"
req.["X-API-Client-Version"] = STREAMBIRD_RUBY_CLIENT_VERSION
end
if response.status != 200 and response.status != 201
return handle_error(response)
end
response
rescue Faraday::Error::ConnectionFailed
raise Streambird::Api::ConnectionError
end
|