Class: Liquid::Network
- Inherits:
-
Object
- Object
- Liquid::Network
- Defined in:
- lib/liquid/network.rb
Constant Summary collapse
- USER_AGENT =
"Liquid/#{Liquid::VERSION} (Ruby ;)"
Instance Method Summary collapse
- #change_token(token) ⇒ Object
- #default_headers ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #generic_request(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(end_point = nil, token = nil) ⇒ Network
constructor
A new instance of Network.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
Constructor Details
#initialize(end_point = nil, token = nil) ⇒ Network
Returns a new instance of Network.
6 7 8 9 10 |
# File 'lib/liquid/network.rb', line 6 def initialize(end_point = nil, token = nil) @headers = default_headers @end_point = end_point change_token token unless token.nil? end |
Instance Method Details
#change_token(token) ⇒ Object
32 33 34 |
# File 'lib/liquid/network.rb', line 32 def change_token(token) @headers['Authorization'] = "Token #{token}" end |
#default_headers ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/liquid/network.rb', line 36 def default_headers { 'User-Agent' => USER_AGENT, 'Accept' => 'application/vnd.lqd.v1+json', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip', 'Authorization' => 'Token ' } end |
#delete(path, params = {}) ⇒ Object
24 25 26 |
# File 'lib/liquid/network.rb', line 24 def delete(path, params = {}) parse(generic_request(path).delete params, &handle_error) end |
#generic_request(path) ⇒ Object
28 29 30 |
# File 'lib/liquid/network.rb', line 28 def generic_request(path) RestClient::Resource.new("#{@end_point}#{path}", headers: @headers) end |
#get(path) ⇒ Object
12 13 14 |
# File 'lib/liquid/network.rb', line 12 def get(path) parse(generic_request(path).get(&handle_error)) end |
#post(path, params = {}) ⇒ Object
16 17 18 |
# File 'lib/liquid/network.rb', line 16 def post(path, params = {}) parse(generic_request(path).post params, &handle_error) end |
#put(path, params = {}) ⇒ Object
20 21 22 |
# File 'lib/liquid/network.rb', line 20 def put(path, params = {}) parse(generic_request(path).put params, &handle_error) end |