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

Returns a new instance of API.



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

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

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



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

def 
  @account
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



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

def credentials
  @credentials
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#check_synchronization(import_id) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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

#initialize_optionsObject



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

def initialize_options
  @options = OpenStruct.new
end

#send_query(query) ⇒ Object



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

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