Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/client.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#format ⇒ Object
Returns the value of attribute format.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#unwrap ⇒ Object
Returns the value of attribute unwrap.
Class Method Summary collapse
-
.hash2ostruct(object) ⇒ Object
Recursively create ostruct obj from httparty’s Hash/Array mess.
Instance Method Summary collapse
- #body ⇒ Object
- #get(url) ⇒ Object
- #get_and_unwrap(url, unwrap) ⇒ Object
- #headers ⇒ Object
-
#initialize(base, format) ⇒ Client
constructor
A new instance of Client.
- #post(url, body) ⇒ Object
- #raw_response ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(base, format) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/client.rb', line 6 def initialize(base,format) @base = base @format = format end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
4 5 6 |
# File 'lib/client.rb', line 4 def base @base end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/client.rb', line 4 def format @format end |
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/client.rb', line 4 def raw @raw end |
#unwrap ⇒ Object
Returns the value of attribute unwrap.
4 5 6 |
# File 'lib/client.rb', line 4 def unwrap @unwrap end |
Class Method Details
.hash2ostruct(object) ⇒ Object
Recursively create ostruct obj from httparty’s Hash/Array mess.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/client.rb', line 54 def self.hash2ostruct(object) return case object when Hash object = object.clone object.each do |key, value| object[key] = Client.hash2ostruct(value) end OpenStruct.new(object) when Array object = object.clone object.map! { |i| Client.hash2ostruct(i) } else object end end |
Instance Method Details
#body ⇒ Object
44 45 46 |
# File 'lib/client.rb', line 44 def body @raw.body end |
#get(url) ⇒ Object
16 17 18 19 |
# File 'lib/client.rb', line 16 def get(url) @raw = HTTParty.get("#{@base}#{url}") self end |
#get_and_unwrap(url, unwrap) ⇒ Object
11 12 13 14 |
# File 'lib/client.rb', line 11 def get_and_unwrap(url,unwrap) @unwrap = unwrap get(url) end |
#headers ⇒ Object
40 41 42 |
# File 'lib/client.rb', line 40 def headers Client.hash2ostruct(@raw.headers) end |
#post(url, body) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/client.rb', line 21 def post(url,body) # TODO: remove. This is simply for my testing. url = 'http://localhost:3000/open311/requests.xml' @raw = HTTParty.post(url, :body => body) self end |
#raw_response ⇒ Object
36 37 38 |
# File 'lib/client.rb', line 36 def raw_response Client.hash2ostruct(@raw.parsed_response) end |
#request ⇒ Object
48 49 50 |
# File 'lib/client.rb', line 48 def request @raw.request end |