Class: Cartowrap::API

Inherits:
Object
  • Object
show all
Defined in:
lib/cartowrap/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, account = nil) ⇒ API



3
4
5
6
7
8
9
10
# File 'lib/cartowrap/api.rb', line 3

def initialize(api_key = nil,  = nil)
  @api_key = api_key || Cartowrap.config.api_key
  @account =  || Cartowrap.config.
  @credentials = {}
  @credentials['api_key'] = @api_key
  @credentials['account'] = @account
  @options = OpenStruct.new
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



12
13
14
# File 'lib/cartowrap/api.rb', line 12

def 
  @account
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/cartowrap/api.rb', line 12

def api_key
  @api_key
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



12
13
14
# File 'lib/cartowrap/api.rb', line 12

def credentials
  @credentials
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/cartowrap/api.rb', line 12

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



12
13
14
# File 'lib/cartowrap/api.rb', line 12

def response
  @response
end

Instance Method Details

#check_synchronization(import_id) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/cartowrap/api.rb', line 38

def check_synchronization(import_id)
  options.endpoint = "import"
  options.query_string = false
  options.http_method = 'get'
  options.resource_id = "#{import_id}/sync_now"
  result = make_call(options)
  result
end

#create_synchronization(url, interval, sync_options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cartowrap/api.rb', line 56

def create_synchronization(url, interval, sync_options={})
  validate_sync_options(sync_options) if sync_options
  options.endpoint = "import"
  options.type_guessing = sync_options[:type_guessing]
  options.quoted_fields_guessing = sync_options[:quoted_fields_guessing]
  options.content_guessing = sync_options[:content_guessing]
  options.query_string = false
  options.url = url
  options.interval = interval
  options.http_method = 'post'
  result = make_call(options)
  result
end

#delete_synchronization(import_id) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/cartowrap/api.rb', line 70

def delete_synchronization(import_id)
  options.endpoint = "import"
  options.resource_id = import_id
  options.query_string = false
  options.http_method = 'delete'
  result = make_call(options)
  result
end

#force_synchronization(import_id) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/cartowrap/api.rb', line 47

def force_synchronization(import_id)
  options.endpoint = "import"
  options.query_string = false
  options.http_method = 'put'
  options.resource_id = "#{import_id}/sync_now"
  result = make_call(options)
  result
end

#get_synchronization(import_id) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/cartowrap/api.rb', line 29

def get_synchronization(import_id)
  options.endpoint = "import"
  options.import_id = import_id
  options.query_string = false
  options.http_method = 'get'
  result = make_call(options)
  result
end

#get_synchronizationsObject



22
23
24
25
26
27
# File 'lib/cartowrap/api.rb', line 22

def get_synchronizations
  options.endpoint = "import"
  options.query_string = false
  result = make_call(options)
  result
end

#initialize_optionsObject



79
80
81
# File 'lib/cartowrap/api.rb', line 79

def initialize_options
  @options = OpenStruct.new
end

#send_query(query) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cartowrap/api.rb', line 14

def send_query(query)
  options.endpoint = "sql"
  options.query_string = true
  options.q = query
  result = make_call(options)
  result
end