Class: Rapidash::Base
- Inherits:
-
Object
- Object
- Rapidash::Base
- Includes:
- Resourceable, Urlable
- Defined in:
- lib/rapidash/base.rb
Class Attribute Summary collapse
-
.root_element ⇒ Object
Returns the value of attribute root_element.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #call! ⇒ Object
- #create!(params) ⇒ Object
- #delete! ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #update!(params) ⇒ Object
Methods included from Resourceable
included, #resource, #resource!
Methods included from Urlable
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rapidash/base.rb', line 16 def initialize(*args) @client, @id, = args if @id.is_a?(Hash) = @id @id = nil end @options ||= {} @options.merge!( || {}) @url = "#{base_url}#{resource_url}" @url += "/#{@id}" if @id end |
Class Attribute Details
.root_element ⇒ Object
Returns the value of attribute root_element.
9 10 11 |
# File 'lib/rapidash/base.rb', line 9 def root_element @root_element end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/rapidash/base.rb', line 6 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/rapidash/base.rb', line 6 def @options end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/rapidash/base.rb', line 6 def url @url end |
Class Method Details
.root(name) ⇒ Object
11 12 13 |
# File 'lib/rapidash/base.rb', line 11 def root(name) @root_element = name.to_sym end |
Instance Method Details
#call! ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rapidash/base.rb', line 48 def call! self. ||= {} .delete(:previous_url) [:headers] ||= {} [:headers]["content-type"] = "application/json" method = .delete(:method) || :get client.send(method, url, ) end |
#create!(params) ⇒ Object
30 31 32 33 34 |
# File 'lib/rapidash/base.rb', line 30 def create!(params) [:method] = :post set_body!(params) call! end |
#delete! ⇒ Object
42 43 44 45 |
# File 'lib/rapidash/base.rb', line 42 def delete! [:method] = :delete call! end |
#update!(params) ⇒ Object
36 37 38 39 40 |
# File 'lib/rapidash/base.rb', line 36 def update!(params) [:method] = client.class.patch ? :patch : :put set_body!(params) call! end |