Class: CaseblocksAPI::Client
- Inherits:
-
Object
- Object
- CaseblocksAPI::Client
- Includes:
- HTTParty
- Defined in:
- lib/caseblocks_api.rb,
lib/caseblocks_api/searcher.rb,
lib/caseblocks_api/get_cases.rb,
lib/caseblocks_api/update_case.rb,
lib/caseblocks_api/bucket_results.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #bucket_results(bucket_name) ⇒ Object
- #create_case(params, case_type = nil) ⇒ Object
- #create_message(params) ⇒ Object
- #find_or_create_case(params, case_type = nil) ⇒ Object
- #get_cases(ids) ⇒ Object
-
#initialize(email, password, url) ⇒ Client
constructor
A new instance of Client.
- #search(case_type, criteria, options = {}) ⇒ Object
- #update_case(case_type, id, params) ⇒ Object
Constructor Details
#initialize(email, password, url) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/caseblocks_api.rb', line 21 def initialize(email, password, url) self.class.base_uri url result = self.class.post("/tokens", :body => {email: email, password: password}.to_json) if result["message"] raise CaseblocksAPI::AuthenticationException.new(result["message"]) else @auth_token = result["token"] if result self.class.default_params("auth_token" => @auth_token) end end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
16 17 18 |
# File 'lib/caseblocks_api.rb', line 16 def auth_token @auth_token end |
Instance Method Details
#bucket_results(bucket_name) ⇒ Object
18 19 20 |
# File 'lib/caseblocks_api/bucket_results.rb', line 18 def bucket_results(bucket_name) BucketResults.new(self.class).execute(bucket_name) end |
#create_case(params, case_type = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/caseblocks_api.rb', line 32 def create_case(params, case_type=nil) params.merge!(:case_type_id => fetch_case_type_id(case_type)) response = self.class.post("/case_blocks/cases", :body => {:case => params}.to_json) if response.code != 201 response_hash = {:body => response.body, :code => response.code, :message => response., :headers => response.headers.inspect} raise CaseblocksAPI::CaseCreationError.new("Unable to create case - received response code #{response.code}", response_hash) end response end |
#create_message(params) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/caseblocks_api.rb', line 52 def (params) query = {:message => params} response = self.class.post("/case_blocks/messages", :body => query.to_json) if response.code != 201 response_hash = {:body => response.body, :code => response.code, :message => response., :headers => response.headers.inspect} raise CaseblocksAPI::CaseCreationError.new("Unable to create message - received response code #{response.code}", response_hash) else return response["message"] end end |
#find_or_create_case(params, case_type = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/caseblocks_api.rb', line 42 def find_or_create_case(params, case_type=nil) params.merge!(:case_type_id => fetch_case_type_id(case_type)) response = self.class.post("/case_blocks/cases", :body => {:unique => true, :case => params}.to_json) if response.code != 201 response_hash = {:body => response.body, :code => response.code, :message => response., :headers => response.headers.inspect} raise CaseblocksAPI::CaseCreationError.new("Unable to create case - received response code #{response.code}", response_hash) end response end |
#get_cases(ids) ⇒ Object
17 18 19 |
# File 'lib/caseblocks_api/get_cases.rb', line 17 def get_cases(ids) GetCases.new(self.class).execute(ids) end |
#search(case_type, criteria, options = {}) ⇒ Object
17 18 19 |
# File 'lib/caseblocks_api/searcher.rb', line 17 def search(case_type, criteria, ={}) Searcher.new(self.class).execute_search(case_type, criteria, ) end |
#update_case(case_type, id, params) ⇒ Object
18 19 20 |
# File 'lib/caseblocks_api/update_case.rb', line 18 def update_case(case_type, id, params) UpdateCase.new(self.class).execute(case_type, id, params) end |