Class: SODA::Client
- Inherits:
-
Object
- Object
- SODA::Client
- Defined in:
- lib/soda/client.rb
Instance Method Summary collapse
- #delete(resource, body = nil, params = {}) ⇒ Object
- #get(resource, params = {}) ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #post(resource, body = nil, params = {}) ⇒ Object
- #post_form(path, fields = {}, params = {}) ⇒ Object
- #put(resource, body = nil, params = {}) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/soda/client.rb', line 12 def initialize(config = {}) @config = config.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} end |
Instance Method Details
#delete(resource, body = nil, params = {}) ⇒ Object
28 29 30 |
# File 'lib/soda/client.rb', line 28 def delete(resource, body = nil, params = {}) connection(:delete, resource, body, params) end |
#get(resource, params = {}) ⇒ Object
16 17 18 |
# File 'lib/soda/client.rb', line 16 def get(resource, params = {}) connection(:get, resource, nil, params) end |
#post(resource, body = nil, params = {}) ⇒ Object
20 21 22 |
# File 'lib/soda/client.rb', line 20 def post(resource, body = nil, params = {}) connection(:post, resource, body, params) end |
#post_form(path, fields = {}, params = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/soda/client.rb', line 32 def post_form(path, fields = {}, params = {}) query = query_string(params) resource = resoure_path(path) # Create our request uri = URI.parse("https://#{@config[:domain]}#{resource}.json?#{query}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if @config[:ignore_ssl] http.auth.ssl.verify_mode = openssl::ssl::verify_none end request = Net::HTTP::Post.new(uri.request_uri) request.add_field("X-App-Token", @config[:app_token]) request.set_form_data(fields) # Authenticate if we're supposed to if @config[:username] request.basic_auth @config[:username], @config[:password] end # BAM! return handle_response(http.request(request)) end |
#put(resource, body = nil, params = {}) ⇒ Object
24 25 26 |
# File 'lib/soda/client.rb', line 24 def put(resource, body = nil, params = {}) connection(:put, resource, body, params) end |