Class: Flydata::ApiClient

Inherits:
Object
  • Object
show all
Includes:
Helpers, Singleton
Defined in:
lib/flydata/api_client.rb

Constant Summary

Constants included from Helpers

Helpers::UNIT_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

as_size, development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, flydata_version, format_menu_list, retry_on, to_command_class, usage_text

Constructor Details

#initializeApiClient

Returns a new instance of ApiClient.


16
17
18
19
# File 'lib/flydata/api_client.rb', line 16

def initialize
  @credentials = Flydata::Credentials.new
  read_flydata_api_host
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(cls_name, *args, &block) ⇒ Object

high level api


42
43
44
45
46
47
# File 'lib/flydata/api_client.rb', line 42

def method_missing(cls_name, *args, &block)
  method_name = args.shift.to_s
  require File.join("flydata/api", cls_name.to_s)
  api_cls = "Flydata::Api::#{cls_name.to_s.camelize}".constantize
  api_cls.new(self)
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials


13
14
15
# File 'lib/flydata/api_client.rb', line 13

def credentials
  @credentials
end

#flydata_api_hostObject (readonly)

Returns the value of attribute flydata_api_host


14
15
16
# File 'lib/flydata/api_client.rb', line 14

def flydata_api_host
  @flydata_api_host
end

#responseObject (readonly)

Returns the value of attribute response


12
13
14
# File 'lib/flydata/api_client.rb', line 12

def response
  @response
end

Instance Method Details

#get(path) ⇒ Object


34
35
36
37
38
39
# File 'lib/flydata/api_client.rb', line 34

def get(path)
  uri = generate_auth_url(path)
  resource = RestClient::Resource.new(uri, resource_opts)
  @response = resource.get(:accept => :json)
  handle_response response
end

#post(path, headers = nil, params = nil) ⇒ Object

row level api


22
23
24
25
26
27
# File 'lib/flydata/api_client.rb', line 22

def post(path, headers = nil, params=nil)
  uri = generate_auth_url(path)
  resource = RestClient::Resource.new(uri, resource_opts(headers))
  @response = resource.post(params, :accept => :json)
  handle_response response
end

#put(path, params = nil) ⇒ Object


28
29
30
31
32
33
# File 'lib/flydata/api_client.rb', line 28

def put(path, params=nil)
  uri = generate_auth_url(path)
  resource = RestClient::Resource.new(uri, resource_opts)
  @response = resource.put(params, :accept => :json)
  handle_response response
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

48
# File 'lib/flydata/api_client.rb', line 48

def respond_to_missing?(method_name, include_private=false); true end