Sha256: cc7e8e2ea5c7a12511f7eeef7ca25161fffb5c64d94b3d77863e6cc6bcb903ce
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
require "httparty" require "json" require 'active_support/inflector' require "caseblocks_api/authentication_exception" module CaseblocksAPI require 'caseblocks_api/bucket_results' require 'caseblocks_api/find_by_property' require 'caseblocks_api/update_case' class Client include HTTParty attr_reader :auth_token headers "Accept" => "application/json" headers "Content-Type" => "application/json" 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 def create_case(params, case_type=nil) if case_type case_type_id = get_casetype_id(case_type) end if case_type_id params = params.merge(:case_type_id => case_type_id) end self.class.post("/case_blocks/cases", :body => {:case => params}.to_json) end def get_casetype_id(case_type_name) response = self.class.get("/case_blocks/case_types")["case_types"] response.each do |case_type| if case_type.has_value? case_type_name return case_type["id"] end end nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
caseblocks_api-0.2.2 | lib/caseblocks_api.rb |