Class: Zipmark::Adapters::HTTPClientAdapter
- Inherits:
-
Object
- Object
- Zipmark::Adapters::HTTPClientAdapter
- Defined in:
- lib/zipmark/adapters/httpclient_adapter.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#production ⇒ Object
Returns the value of attribute production.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #api_accept_mime ⇒ Object
- #api_endpoint ⇒ Object
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
- #httpclient ⇒ Object
- #initialize_client ⇒ Object
- #post(path, body) ⇒ Object
- #put(path, body) ⇒ Object
- #successful?(response) ⇒ Boolean
- #url_for(path) ⇒ Object
- #validation_error?(response) ⇒ Boolean
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 10 def password @password end |
#production ⇒ Object
Returns the value of attribute production.
10 11 12 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 10 def production @production end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 10 def username @username end |
Instance Method Details
#api_accept_mime ⇒ Object
30 31 32 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 30 def api_accept_mime "application/vnd.com.zipmark.#{API_VERSION}+json" end |
#api_endpoint ⇒ Object
26 27 28 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 26 def api_endpoint production ? PRODUCTION_API_ENDPOINT : SANDBOX_API_ENDPOINT end |
#delete(path) ⇒ Object
46 47 48 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 46 def delete(path) httpclient.delete(url_for(path)) end |
#get(path) ⇒ Object
34 35 36 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 34 def get(path) httpclient.get(url_for(path)) end |
#httpclient ⇒ Object
12 13 14 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 12 def httpclient @httpclient ||= initialize_client end |
#initialize_client ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 16 def initialize_client client = HTTPClient.new( default_header: { 'Content-Type' => 'application/json', 'Accept' => api_accept_mime }, force_basic_auth: true ) client.ssl_config.ssl_version = :TLSv1 client.set_auth(api_endpoint, username, password) return client end |
#post(path, body) ⇒ Object
38 39 40 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 38 def post(path, body) httpclient.post(url_for(path), :body => body.to_json) end |
#put(path, body) ⇒ Object
42 43 44 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 42 def put(path, body) httpclient.put(url_for(path), :body => body.to_json) end |
#successful?(response) ⇒ Boolean
57 58 59 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 57 def successful?(response) response.code >= 200 && response.code < 300 end |
#url_for(path) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 50 def url_for(path) path = URI.parse(path) if path.kind_of? URI::Generic path = URI.parse(api_endpoint) + path end end |
#validation_error?(response) ⇒ Boolean
61 62 63 |
# File 'lib/zipmark/adapters/httpclient_adapter.rb', line 61 def validation_error?(response) response.code == 422 end |