Class: NinjaBlocks::Base
- Inherits:
-
Object
- Object
- NinjaBlocks::Base
- Defined in:
- lib/ninja_blocks/base.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(url, options = {}) ⇒ Object
- #execute(method, url, options = {}) ⇒ Object
- #get(url, options = {}) ⇒ Object
- #post(url, options = {}) ⇒ Object
- #put(url, options = {}) ⇒ Object
-
#put_json(url, json) ⇒ Object
ugly hack, but I’m too tired to think.
- #token ⇒ Object
Instance Method Details
#connection ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ninja_blocks/base.rb', line 17 def connection @connection = Faraday.new(:url => 'https://api.ninja.is') @connection.headers['accept'] = 'application/json' @connection.headers['Content-Type'] = 'application/json' @connection end |
#delete(url, options = {}) ⇒ Object
13 14 15 |
# File 'lib/ninja_blocks/base.rb', line 13 def delete(url,={}) execute(:delete,url,) end |
#execute(method, url, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ninja_blocks/base.rb', line 28 def execute(method,url,={}) unless .empty? response = connection.send(method,"#{url}?#{}&user_access_token=#{self.token}") else response = connection.send(method,"#{url}?user_access_token=#{self.token}") end JSON.parse(response.body) end |
#get(url, options = {}) ⇒ Object
3 4 5 |
# File 'lib/ninja_blocks/base.rb', line 3 def get(url,={}) execute(:get,url,) end |
#post(url, options = {}) ⇒ Object
9 10 11 |
# File 'lib/ninja_blocks/base.rb', line 9 def post(url,={}) execute(:post,url,) end |
#put(url, options = {}) ⇒ Object
6 7 8 |
# File 'lib/ninja_blocks/base.rb', line 6 def put(url,={}) execute(url, json) end |
#put_json(url, json) ⇒ Object
ugly hack, but I’m too tired to think
38 39 40 41 42 43 |
# File 'lib/ninja_blocks/base.rb', line 38 def put_json(url, json) puts url puts json response = connection.send(:put, "#{url}?user_access_token=#{self.token}", json) puts response end |
#token ⇒ Object
24 25 26 |
# File 'lib/ninja_blocks/base.rb', line 24 def token @token || NinjaBlocks.token end |