Class: Heterocera::Client
- Inherits:
-
Object
- Object
- Heterocera::Client
- Defined in:
- lib/heterocera/heterocera.rb
Constant Summary collapse
- READ =
"read"
- WRITE =
"write"
- TAKE =
"take"
- XML =
get .json for free
".xml"
- GZ =
".gz"
- HTML =
".html"
- OTHER_SUFFIXES =
[XML, GZ, HTML]
Instance Method Summary collapse
-
#initialize(server_address) ⇒ Client
constructor
A new instance of Client.
- #read(tags = [], suffix = "") ⇒ Object
- #server_address ⇒ Object
- #server_address=(server_address) ⇒ Object
- #take!(tags = [], suffix = "") ⇒ Object
- #write!(tags = [], value = "") ⇒ Object
Constructor Details
#initialize(server_address) ⇒ Client
Returns a new instance of Client.
24 25 26 27 |
# File 'lib/heterocera/heterocera.rb', line 24 def initialize server_address @base_address = URI.parse server_address @agent = Mechanize.new end |
Instance Method Details
#read(tags = [], suffix = "") ⇒ Object
37 38 39 |
# File 'lib/heterocera/heterocera.rb', line 37 def read( = [], suffix = "") get_query READ, , suffix end |
#server_address ⇒ Object
29 30 31 |
# File 'lib/heterocera/heterocera.rb', line 29 def server_address @base_address end |
#server_address=(server_address) ⇒ Object
33 34 35 |
# File 'lib/heterocera/heterocera.rb', line 33 def server_address= server_address @base_address = URI.parse server_address end |
#take!(tags = [], suffix = "") ⇒ Object
61 62 63 |
# File 'lib/heterocera/heterocera.rb', line 61 def take!( = [], suffix = "") get_query TAKE, , suffix end |
#write!(tags = [], value = "") ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/heterocera/heterocera.rb', line 41 def write!( = [], value = "") raise ArgumentError, 'You must provide a String or a File' unless value.class == String || value.class == File raise ArgumentError, "You can't use wildcards when writing" if .include? '*' case value.class.to_s when "String" if CGI.escape(value).bytesize < 1024 response = get(WRITE, , value) else response = post(WRITE, , value) end when "File" raise TypeError, 'Please open files in binary mode' unless value.binmode? response = post(WRITE, , value) end JSON.parse response.body end |