Class: Egree::Client

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

Defined Under Namespace

Classes: ErrorResult, SuccessResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, environment = :production) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
# File 'lib/egree/client.rb', line 13

def initialize username, password, environment = :production
  @username = username
  @password = password
  self.environment = environment
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/egree/client.rb', line 11

def environment
  @environment
end

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/egree/client.rb', line 9

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/egree/client.rb', line 9

def username
  @username
end

Instance Method Details

#connectionObject



45
46
47
48
49
50
51
# File 'lib/egree/client.rb', line 45

def connection
  Faraday.new "https://#{host}" do |conn|
    conn.headers["Accept"] = "application/json"
    conn.basic_auth username, password
    conn.adapter :net_http
  end
end

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



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

def create_case signature_case, options = {}
  signature_case_json = Egree::Serializers::CaseSerializer.serialize signature_case, options
  post "/apiv1/createcasecommand", signature_case_json
end

#get_case_url(signature_case) ⇒ Object



24
25
26
27
28
29
# File 'lib/egree/client.rb', line 24

def get_case_url signature_case
  reference_id = signature_case.respond_to?(:reference_id) ? signature_case.reference_id : signature_case.to_s
  reference_id_json = Egree::Serializers::ReferenceIdSerializer.serialize reference_id

  post "/apiv1/getviewcaseurlquery", reference_id_json
end

#headersObject



53
54
55
# File 'lib/egree/client.rb', line 53

def headers
  connection.headers
end

#hostObject



41
42
43
# File 'lib/egree/client.rb', line 41

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

#post(api_command, body = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/egree/client.rb', line 31

def post api_command, body = nil
  response = make_post api_command, body

  if response.success?
    SuccessResult.new response.body
  else
    ErrorResult.new response.body
  end
end