Class: ApphoshiesClient::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/apphoshies_client/base.rb

Direct Known Subclasses

DeviceToken, Document, FileUpload, Message

Class Method Summary collapse

Class Method Details

.all(options = {}) ⇒ Object



14
15
16
# File 'lib/apphoshies_client/base.rb', line 14

def self.all(options = {})
  get(:all, options)
end

.find_by_application_client_key(application_client_key, options = {}) ⇒ Object



20
21
22
23
# File 'lib/apphoshies_client/base.rb', line 20

def self.find_by_application_client_key(application_client_key, options = {})
  default_options = {:app_id => @@apphoshies_configuration.app_id, :application_client_key => application_client_key}
  get(:all, options)
end

.find_by_datasource(datasource, options = {}) ⇒ Object



25
26
27
# File 'lib/apphoshies_client/base.rb', line 25

def self.find_by_datasource(datasource, options = {})
  get(:all, options.merge(:datasource => datasource)) if datasource
end

.find_one(id) ⇒ Object



18
# File 'lib/apphoshies_client/base.rb', line 18

def self.find_one(id); get(id); end

.get(query_symbol, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/apphoshies_client/base.rb', line 2

def self.get(query_symbol, options = {})
  reload_http_headers
  
  if @@apphoshies_configuration.app_id.blank? or @@apphoshies_configuration.username.blank? or @@apphoshies_configuration.api_key.blank?
    raise ApphoshiesClient::MissingCredentialsException, 'Username, API Key and App Id required!'
  end

  return find(query_symbol, :params => {:app_id => @@apphoshies_configuration.app_id}) if query_symbol.is_a?(String)
  default_options = {:app_id => @@apphoshies_configuration.app_id, :limit => 100}
  find(:all, :params => default_options.merge(options))
end

.reload_http_headersObject



29
30
31
32
# File 'lib/apphoshies_client/base.rb', line 29

def self.reload_http_headers
  headers['APH_USERNAME'] = @@apphoshies_configuration.username
  headers['APH_API_KEY'] = @@apphoshies_configuration.api_key
end