Class: Ubiquity::Wiredrive::API::V3::Client
- Inherits:
-
Object
- Object
- Ubiquity::Wiredrive::API::V3::Client
- Defined in:
- lib/ubiquity/wiredrive/api/v3/client.rb,
lib/ubiquity/wiredrive/api/v3/client/requests/base_request.rb
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#client_code ⇒ Object
Returns the value of attribute client_code.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
API METHODS collapse
-
#auth_token(args = { }, options = { }) ⇒ Object
################################################################################################################## #.
- #invitations_get(args = { }, options = { }) ⇒ Object
- #presentation_authorize_get(args = { }, options = { }) ⇒ Object
- #presentation_get(args = { }, options = { }) ⇒ Object
- #users_get(args = { }, options = { }) ⇒ Object
- #users_projects_get(args = { }, options = { }) ⇒ Object
Instance Method Summary collapse
- #auth_token=(value) ⇒ Object
- #error ⇒ Object
- #error_message ⇒ Object
- #errors ⇒ Object
-
#http(method, *args) ⇒ Object
Exposes HTTP Methods.
-
#initialize(args = { }) ⇒ Client
constructor
A new instance of Client.
- #initialize_http_client(args = { }) ⇒ Object
- #initialize_logger(args = { }) ⇒ Object
- #login_and_set_token(args) ⇒ Object
- #process_request(request, options = nil) ⇒ Object
-
#process_request_using_class(request_class, args = { }, options = { }) ⇒ Object
def paginator @paginator ||= Paginator.new(self) if @response end.
- #success? ⇒ Boolean
- #token_cache_read(args) ⇒ Object
- #token_cache_write(args) ⇒ Object
Constructor Details
#initialize(args = { }) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 12 def initialize(args = { }) _token_cache = args.fetch(:token_cache_allow, false) _token = args[:auth_token] || _token_cache ? token_cache_read(args) : nil args[:auth_token] = _token if _token.is_a?(String) # _token.is_a?(String) ? Token.new(_token, self) : _token if _token initialize_logger(args) initialize_http_client(args) unless _token _do_login = args.fetch(:do_login, true) if _do_login _token = login_and_set_token(args) args[:auth_token] = _token token_cache_write(args) if _token_cache && _token end end end |
Instance Attribute Details
#client_code ⇒ Object
Returns the value of attribute client_code.
10 11 12 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 10 def client_code @client_code end |
#http_client ⇒ Object
Returns the value of attribute http_client.
10 11 12 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 10 def http_client @http_client end |
#http_response ⇒ Object
Returns the value of attribute http_response.
10 11 12 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 10 def http_response @http_response end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 8 def logger @logger end |
#request ⇒ Object
Returns the value of attribute request.
10 11 12 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 10 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
10 11 12 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 10 def response @response end |
Instance Method Details
#auth_token(args = { }, options = { }) ⇒ Object
################################################################################################################## #
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 161 def auth_token(args = { }, = { }) _request = Requests::BaseRequest.new( args, { :http_path => 'auth/api-token-auth', :http_method => :post, :default_parameter_send_in_value => :body, :parameters => [ { :name => :client_code, :required => true, :default_value => client_code }, { :name => :username, :required => true }, { :name => :password, :required => true } ] }.merge() ) _initial_http_host_address = http_client.http_host_address client_code = _request.arguments[:client_code] _http_host_address = "#{client_code}.wiredrive.com" http_client.http_host_address = _http_host_address _response = process_request(_request, ) http_client.http_host_address = _initial_http_host_address _token = http_client.response['Authorization'] _token || _response end |
#auth_token=(value) ⇒ Object
154 155 156 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 154 def auth_token=(value) http_client.auth_token = value end |
#error ⇒ Object
130 131 132 133 134 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 130 def error _error = errors.first return _error.inspect if _error.is_a?(Hash) _error end |
#error_message ⇒ Object
136 137 138 139 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 136 def _error = error _error.is_a?(Hash) ? (_error['message'] || _error) : _error end |
#errors ⇒ Object
141 142 143 144 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 141 def errors return (response['errors'] || [ ]) if response.is_a?(Hash) [ ] end |
#http(method, *args) ⇒ Object
Exposes HTTP Methods
113 114 115 116 117 118 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 113 def http(method, *args) @request = nil @response = http_client.send(method, *args) @request = http_client.request response end |
#initialize_http_client(args = { }) ⇒ Object
69 70 71 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 69 def initialize_http_client(args = { }) @http_client = Ubiquity::Wiredrive::API::V3::HTTPClient.new(args) end |
#initialize_logger(args = { }) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 59 def initialize_logger(args = { }) @logger = args[:logger] ||= Logger.new(args[:log_to] || STDOUT) log_level = args[:log_level] if log_level @logger.level = log_level args[:logger] = @logger end @logger end |
#invitations_get(args = { }, options = { }) ⇒ Object
186 187 188 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 186 def invitations_get(args = { }, = { }) end |
#login_and_set_token(args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 47 def login_and_set_token(args) _credentials = args[:credentials] || args _client_code = _credentials[:client_code] _username = _credentials[:username] _password = _credentials[:password] if _client_code && _username && _password token_data = auth_token(_credentials) self.auth_token = token_data end token_data end |
#presentation_authorize_get(args = { }, options = { }) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 190 def (args = { }, = { }) _request = Requests::BaseRequest.new( args, { :http_path => 'presentation-orch-api/api/authorize/#{path_arguments[:invite_token]}', :default_parameter_send_in_value => :path, :parameters => [ { :name => :invite_token, :aliases => [ :token ], :required => true }, { :name => :password, :required => true, :send_in => :query } ] }.merge() ) _response = process_request(_request, ) _token = http_client.response['Authorization'] _token || _response end |
#presentation_get(args = { }, options = { }) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 207 def presentation_get(args = { }, = { }) _request = Requests::BaseRequest.new( args, { :http_path => 'presentation-orch-api/api/presentations/#{path_arguments[:presentation_id]}', :default_parameter_send_in_value => :path, :parameters => [ { :name => :presentation_id, :aliases => [ :id ], :required => true } ] }.merge() ) process_request(_request, ) end |
#process_request(request, options = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 78 def process_request(request, = nil) # @paginator = nil @response = nil @request = request logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty? # if ([:all, 'all'].include?(request.arguments[:_page])) # request.arguments[:_page] = 1 # include_remaining_pages = true # else # include_remaining_pages = false # end request.client = self unless request.client ||= request. return (.fetch(:return_request, true) ? request : nil) unless .fetch(:execute_request, true) #@response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options) @response = request.execute # if include_remaining_pages # return paginator.include_remaining_pages # end if @response.is_a?(Hash) _results = @response['results'] return _results if _results end @response end |
#process_request_using_class(request_class, args = { }, options = { }) ⇒ Object
def paginator
@paginator ||= Paginator.new(self) if @response
end
124 125 126 127 128 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 124 def process_request_using_class(request_class, args = { }, = { }) @response = nil @request = request_class.new(args, ) process_request(request, ) end |
#success? ⇒ Boolean
146 147 148 149 150 151 152 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 146 def success? return unless request return request.success? if request.respond_to?(:success?) _code = http_client.response.code _code and _code.start_with?('2') end |
#token_cache_read(args) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 31 def token_cache_read(args) _token_path = args[:token_cache_path] || '_token.yaml' _token_path = File.(_token_path) _token = File.exists?(_token_path) ? YAML.load_file(_token_path) : nil _token end |
#token_cache_write(args) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 38 def token_cache_write(args) _token = args[:auth_token] return unless _token _token_path = args[:token_cache_path] || '_token.yaml' _token_path = File.(_token_path) logger.debug { "Writing Token Cache - '#{_token_path}'" } File.open(_token_path, 'w') { |f| f.write(YAML.dump(_token)) } end |
#users_get(args = { }, options = { }) ⇒ Object
221 222 223 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 221 def users_get(args = { }, = { }) http(:get, 'user-orch-api/api/users') end |
#users_projects_get(args = { }, options = { }) ⇒ Object
225 226 227 |
# File 'lib/ubiquity/wiredrive/api/v3/client.rb', line 225 def users_projects_get(args = { }, = { }) http(:get, 'user-orch-api/api/users/projects') end |