Class: Assently::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/assently/client.rb

Defined Under Namespace

Classes: ErrorResult, SuccessResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, environment = :production) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/assently/client.rb', line 12

def initialize api_key, api_secret, environment = :production
  @api_key = api_key
  @api_secret = api_secret
  self.environment = environment
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/assently/client.rb', line 8

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



8
9
10
# File 'lib/assently/client.rb', line 8

def api_secret
  @api_secret
end

#environmentObject

Returns the value of attribute environment.



10
11
12
# File 'lib/assently/client.rb', line 10

def environment
  @environment
end

Instance Method Details

#connectionObject



44
45
46
47
48
# File 'lib/assently/client.rb', line 44

def connection
  HTTP.
    headers(accept: "application/json").
    basic_auth(user: api_key, pass: api_secret)
end

#create_case(signature_case, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/assently/client.rb', line 18

def create_case signature_case, options = {}
  signature_case_json = Assently::Serializers::CaseSerializer.serialize signature_case, options

  post "/api/v2/createcase", signature_case_json
end

#get(api_command, parameters = {}) ⇒ Object



36
37
38
# File 'lib/assently/client.rb', line 36

def get api_command, parameters = {}
  make_response make_get(api_command, parameters)
end

#get_case(id) ⇒ Object



28
29
30
# File 'lib/assently/client.rb', line 28

def get_case id
  get "/api/v2/getcase", { id: id }
end

#headersObject



50
51
52
# File 'lib/assently/client.rb', line 50

def headers
  connection.headers
end

#hostObject



40
41
42
# File 'lib/assently/client.rb', line 40

def host
  hosts.fetch(self.environment, hosts[:production])
end

#post(api_command, body = nil) ⇒ Object



32
33
34
# File 'lib/assently/client.rb', line 32

def post api_command, body = nil
  make_response make_post(api_command, body)
end

#send_case(id) ⇒ Object



24
25
26
# File 'lib/assently/client.rb', line 24

def send_case id
  post "/api/v2/sendcase", JSON.pretty_generate({ id: id })
end