Class: Zipmark::Adapters::HTTPartyAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/zipmark/adapters/httparty_adapter.rb

Overview

Public: The HTTParty Adapter.

Important Note: PUT is broken in HTTParty when using Digest Auth

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



14
15
16
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 14

def password
  @password
end

#productionObject

Returns the value of attribute production.



14
15
16
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 14

def production
  @production
end

#usernameObject

Returns the value of attribute username.



14
15
16
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 14

def username
  @username
end

Instance Method Details

#api_accept_mimeObject



20
21
22
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 20

def api_accept_mime
  "application/vnd.com.zipmark.#{API_VERSION}+json"
end

#api_endpointObject



16
17
18
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 16

def api_endpoint
  production ? PRODUCTION_API_ENDPOINT : SANDBOX_API_ENDPOINT
end

#delete(path) ⇒ Object



36
37
38
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 36

def delete(path)
  self.class.delete(path, adapter_options)
end

#get(path) ⇒ Object



24
25
26
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 24

def get(path)
  self.class.get(path, adapter_options)
end

#post(path, body) ⇒ Object



28
29
30
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 28

def post(path, body)
  self.class.post(path, adapter_options.merge(:body => body.to_json))
end

#put(path, body) ⇒ Object



32
33
34
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 32

def put(path, body)
  self.class.put(path, adapter_options.merge(:body => body.to_json))
end

#successful?(response) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 40

def successful?(response)
  response.code >= 200 && response.code < 300
end

#validation_error?(response) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/zipmark/adapters/httparty_adapter.rb', line 44

def validation_error?(response)
  response.code == 422
end