Class: CrateAPI::Base
- Inherits:
-
Object
- Object
- CrateAPI::Base
- Includes:
- HTTMultiParty
- Defined in:
- lib/crate_api/base.rb
Overview
Base class which is used to authenticate user and perform calls.
Constant Summary collapse
- API_VERSION =
Current API Version.
1
- BASE_URL =
Base URL Endpoint
"https://api.letscrate.com/#{API_VERSION}"
- AUTH_URL =
Authorization URL Endpoint.
"#{BASE_URL}/users/authenticate.json"
- ITEMS_URL =
Items URL Endpoint.
"#{BASE_URL}/files"
- CRATES_URL =
Crates URL Endpoint.
"#{BASE_URL}/crates"
- SHORT_URL =
Short URL Placeholder String.
"http://lts.cr/%s"
Instance Attribute Summary collapse
Class Method Summary collapse
-
.authorized?(user, pass) ⇒ Boolean
Class method that will return a boolean whether or not the user is authorized.
-
.call(url, verb, params = {}) ⇒ Object
Class method that return the response body of the call.
Instance Method Summary collapse
-
#crates ⇒ CrateAPI::Crates
Default initializer for getting a Crates instance.
-
#initialize(username, password) ⇒ CrateAPI::Base
constructor
Default initializer for the CrateAPI Client.
-
#items ⇒ CrateAPI::Items
Default initializer for getting a Items instance.
Constructor Details
#initialize(username, password) ⇒ CrateAPI::Base
Default initializer for the CrateAPI Client
41 42 43 44 |
# File 'lib/crate_api/base.rb', line 41 def initialize(username, password) raise NotValidUserError unless CrateAPI::Base.(username, password) @@auth = {:username => username, :password => password} end |
Instance Attribute Details
#auth ⇒ Object
13 14 15 |
# File 'lib/crate_api/base.rb', line 13 def auth @auth end |
Class Method Details
.authorized?(user, pass) ⇒ Boolean
Class method that will return a boolean whether or not the user is authorized.
72 73 74 75 76 77 78 |
# File 'lib/crate_api/base.rb', line 72 def self.(user, pass) resp = self.get("#{AUTH_URL}", {:basic_auth => {:username => user, :password => pass}}) if resp.code == 401 return false end return true end |
.call(url, verb, params = {}) ⇒ Object
Class method that return the response body of the call.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/crate_api/base.rb', line 53 def self.call(url, verb, params={}) params.merge!({:basic_auth => @@auth}) resp = nil case verb when :get resp = self.get(url, params) when :post resp = self.post(url, params) end if resp.code == 200 return resp.body end end |
Instance Method Details
#crates ⇒ CrateAPI::Crates
Default initializer for getting a Crates instance.
29 |
# File 'lib/crate_api/base.rb', line 29 def crates(); @crates || CrateAPI::Crates.new(); end |
#items ⇒ CrateAPI::Items
Default initializer for getting a Items instance.
33 |
# File 'lib/crate_api/base.rb', line 33 def items(); @items || CrateAPI::Items.new(); end |