Class: Songdrop::HTTP
- Inherits:
-
Object
- Object
- Songdrop::HTTP
- Defined in:
- lib/songdrop/http/bubblewrap.rb,
lib/songdrop/http/rest-client.rb
Class Method Summary collapse
- .delete(url, params = {}, &block) ⇒ Object
- .get(url, params = {}, &block) ⇒ Object
- .http_request(method, url, options = {}, &block) ⇒ Object
- .post(url, params = {}, &block) ⇒ Object
- .put(url, params = {}, &block) ⇒ Object
Class Method Details
.delete(url, params = {}, &block) ⇒ Object
16 17 18 |
# File 'lib/songdrop/http/bubblewrap.rb', line 16 def self.delete(url, params={}, &block) http_request(:delete, url, params, &block) end |
.get(url, params = {}, &block) ⇒ Object
4 5 6 |
# File 'lib/songdrop/http/bubblewrap.rb', line 4 def self.get(url, params={}, &block) http_request(:get, url, params, &block) end |
.http_request(method, url, options = {}, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/songdrop/http/bubblewrap.rb', line 20 def self.http_request(method, url, ={}, &block) = {:payload => } .merge!({:headers => {:Accept => "application/json"}}) puts "[Songdrop::HTTP] #{method} #{url} with: #{bw_options.inspect}" BubbleWrap::HTTP.send(method, url, ) do |response| if response.ok? block.call response.body.to_str, nil else block.call nil, response.body.to_str end end end |
.post(url, params = {}, &block) ⇒ Object
8 9 10 |
# File 'lib/songdrop/http/bubblewrap.rb', line 8 def self.post(url, params={}, &block) http_request(:post, url, params, &block) end |
.put(url, params = {}, &block) ⇒ Object
12 13 14 |
# File 'lib/songdrop/http/bubblewrap.rb', line 12 def self.put(url, params={}, &block) http_request(:put, url, params, &block) end |