Class: Apidone::Client::Connection
- Inherits:
-
Object
- Object
- Apidone::Client::Connection
- Defined in:
- lib/apidone-client/connection.rb
Constant Summary collapse
- API_DONE_URL =
"apidone.com"
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
Instance Method Summary collapse
- #create(name, data = {}) ⇒ Object
- #delete(name, id) ⇒ Object
- #endpoint_url ⇒ Object
-
#initialize(subdomain) ⇒ Connection
constructor
A new instance of Connection.
- #list(name) ⇒ Object
- #show(name, id) ⇒ Object
- #update(name, id, data = {}) ⇒ Object
Constructor Details
#initialize(subdomain) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 14 15 16 17 |
# File 'lib/apidone-client/connection.rb', line 9 def initialize(subdomain) @subdomain = subdomain @conn = Faraday.new(:url => self.endpoint_url) do |faraday| faraday.request :url_encoded # form-encode POST params #faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
7 8 9 |
# File 'lib/apidone-client/connection.rb', line 7 def conn @conn end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
7 8 9 |
# File 'lib/apidone-client/connection.rb', line 7 def subdomain @subdomain end |
Instance Method Details
#create(name, data = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/apidone-client/connection.rb', line 23 def create(name, data = {}) response = @conn.post "/#{name}", data if response.status == 201 json_response = JSON.parse(response.body) data[:id] = json_response["id"] end show(name, data[:id]) end |
#delete(name, id) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/apidone-client/connection.rb', line 51 def delete(name , id) response = @conn.delete "/#{name}/#{id}" if response.status == 204 return true end end |
#endpoint_url ⇒ Object
19 20 21 |
# File 'lib/apidone-client/connection.rb', line 19 def endpoint_url "http://#{subdomain}.#{API_DONE_URL}" end |
#list(name) ⇒ Object
40 41 42 43 44 |
# File 'lib/apidone-client/connection.rb', line 40 def list(name) response = @conn.get "/#{name}" collection = JSON.parse response.body collection.collect{|o| Apidone::Client::Resource.new(o)} end |