Class: Connection
- Inherits:
-
Object
- Object
- Connection
- Defined in:
- lib/bush_viper/connection.rb
Instance Method Summary collapse
- #get(endpoint) ⇒ Object
-
#initialize(url, token) ⇒ Connection
constructor
A new instance of Connection.
- #patch(endpoint, params) ⇒ Object
- #post(endpoint, file, filename) ⇒ Object
Constructor Details
#initialize(url, token) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 |
# File 'lib/bush_viper/connection.rb', line 5 def initialize(url, token) self.connection = Faraday.new(url: url) self.token = token end |
Instance Method Details
#get(endpoint) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/bush_viper/connection.rb', line 10 def get(endpoint) result = connection.get do |request| request.url endpoint request.headers["Authorization"] = "Bearer #{token}" end MultiJson.load(result.body) end |
#patch(endpoint, params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bush_viper/connection.rb', line 29 def patch(endpoint, params) params = MultiJson.dump(params) result = connection.patch do |request| request.url endpoint request.headers["Authorization"] = "Bearer #{token}" request.headers['Content-Type'] = "application/vnd.mendeley-document.1+json" request.body = params end MultiJson.load(result.body) end |
#post(endpoint, file, filename) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bush_viper/connection.rb', line 18 def post(endpoint, file, filename) result = connection.post do |request| request.url endpoint request.headers["Content-Disposition"] = %Q{attachment; filename="#{filename}"} request.headers["Authorization"] = "Bearer #{token}" request.headers["Content-Type"] = "application/pdf" request.body = file end MultiJson.load(result.body) end |