Class: JustFootball::Acceptance::Adapters::Base
- Inherits:
-
Object
- Object
- JustFootball::Acceptance::Adapters::Base
- Defined in:
- lib/adapters/base.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #del(url) ⇒ Object
- #get(url) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #make_json(input) ⇒ Object
- #make_response(response) ⇒ Object
- #post(url, body) ⇒ Object
- #put(url, body) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/adapters/base.rb', line 9 def initialize @connection = Faraday.new(:url => endpoint) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/adapters/base.rb', line 7 def connection @connection end |
Instance Method Details
#del(url) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/adapters/base.rb', line 46 def del url connection.delete do |request| request.url url request.headers['Content-Type'] = 'application/json' end end |
#get(url) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/adapters/base.rb', line 37 def get url response = connection.get do |request| request.url url request.headers['Content-Type'] = 'application/json' end make_response response end |
#make_json(input) ⇒ Object
53 54 55 |
# File 'lib/adapters/base.rb', line 53 def make_json input JSON.parse input, { symbolize_names: true } end |
#make_response(response) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/adapters/base.rb', line 57 def make_response response { status: response.status, body: make_json(response.body) } end |
#post(url, body) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/adapters/base.rb', line 17 def post url, body response = connection.post do |request| request.url url request.headers['Content-Type'] = 'application/json' request.body = body.to_json end make_response response end |
#put(url, body) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/adapters/base.rb', line 27 def put url, body response = connection.put do |request| request.url url request.headers['Content-Type'] = 'application/json' request.body = body.to_json end make_response response end |