Class: Spire::API
- Inherits:
-
Object
- Object
- Spire::API
- Includes:
- Requestable
- Defined in:
- lib/spire/api.rb,
lib/spire/api/event.rb,
lib/spire/api/member.rb,
lib/spire/api/account.rb,
lib/spire/api/channel.rb,
lib/spire/api/session.rb,
lib/spire/api/resource.rb,
lib/spire/api/application.rb,
lib/spire/api/requestable.rb,
lib/spire/api/notification.rb,
lib/spire/api/subscription.rb
Defined Under Namespace
Modules: Requestable Classes: Account, Application, Channel, Event, Join, Member, Message, Notification, Part, Resource, Session, Subscription
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
HTTP client.
-
#description ⇒ Object
readonly
Description of the Spire.io API from discovery.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_account(info) ⇒ Object
Register for a new spire account, and authenticates as the newly created account.
- #create_session(secret) ⇒ Object
- #discover ⇒ Object
-
#get_application(application_key) ⇒ Object
Gets an application resource from a key without requiring any authentication.
-
#initialize(url = "https://api.spire.io", spire = nil, options = {}) ⇒ API
constructor
A new instance of API.
-
#login(login, password) ⇒ Object
Authenticates a session using a login and password.
- #mediaType(name) ⇒ Object
- #password_reset_request(email) ⇒ Object
Methods included from Requestable
Constructor Details
#initialize(url = "https://api.spire.io", spire = nil, options = {}) ⇒ API
Returns a new instance of API.
35 36 37 38 39 40 |
# File 'lib/spire/api.rb', line 35 def initialize(url="https://api.spire.io", spire=nil, ={}) @version = [:version] || "1.0" @client = Excon @url = url @spire = spire end |
Instance Attribute Details
#client ⇒ Object (readonly)
HTTP client.
33 34 35 |
# File 'lib/spire/api.rb', line 33 def client @client end |
#description ⇒ Object (readonly)
Description of the Spire.io API from discovery.
33 |
# File 'lib/spire/api.rb', line 33 attr_reader :client, :description, :schema |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
33 |
# File 'lib/spire/api.rb', line 33 attr_reader :client, :description, :schema |
Class Method Details
.deserialize(string) ⇒ Object
23 24 25 |
# File 'lib/spire/api.rb', line 23 def self.deserialize(string) JSON.parse(string, :symbolize_names => false) end |
Instance Method Details
#create_account(info) ⇒ Object
Register for a new spire account, and authenticates as the newly created account
151 152 153 154 155 156 157 158 |
# File 'lib/spire/api.rb', line 151 def create_account(info) response = request(:create_account, info) if response.status != 201 raise "Error attempting to register: (#{response.status}) #{response.body}" end session_data = response.data API::Session.new(self, session_data) end |
#create_session(secret) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/spire/api.rb', line 133 def create_session(secret) response = request(:create_session, secret) raise "Error starting a secret-based session" if response.status != 201 session_data = response.data API::Session.new(self, session_data) end |
#discover ⇒ Object
122 123 124 125 126 127 |
# File 'lib/spire/api.rb', line 122 def discover response = request(:discover) raise "Error during discovery: #{response.status}" if response.status != 200 @description = response.data @schema = @description["schema"][@version] end |
#get_application(application_key) ⇒ Object
Gets an application resource from a key without requiring any authentication
170 171 172 173 174 175 176 |
# File 'lib/spire/api.rb', line 170 def get_application(application_key) response = request(:get_application, application_key) if response.status != 200 raise "Error attempting to retrieve application (#{response.status}) #{response.body}" end API::Application.new(self, response.data) end |
#login(login, password) ⇒ Object
Authenticates a session using a login and password
141 142 143 144 145 146 |
# File 'lib/spire/api.rb', line 141 def login(login, password) response = request(:login, login, password) raise "Error attemping to login: (#{response.status}) #{response.body}" if response.status != 201 session_data = response.data API::Session.new(self, session_data) end |
#mediaType(name) ⇒ Object
129 130 131 |
# File 'lib/spire/api.rb', line 129 def mediaType(name) schema[name]["mediaType"] end |
#password_reset_request(email) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/spire/api.rb', line 160 def password_reset_request(email) response = request(:password_reset) unless response.status == 202 raise "Error requesting password reset: (#{response.status}) #{response.body}" end response end |