globase 0.0.0.pre2 → 0.0.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Find Results +89 -0
- data/Gemfile.lock +1 -1
- data/lib/globase.rb +5 -3
- data/lib/globase/base.rb +165 -0
- data/lib/globase/campaign.rb +22 -4
- data/lib/globase/list.rb +20 -0
- data/lib/globase/list_profile.rb +28 -0
- data/lib/globase/list_schema.rb +24 -0
- data/lib/globase/list_segment.rb +24 -0
- data/lib/globase/nested_resource.rb +100 -0
- data/lib/globase/resource.rb +39 -136
- data/lib/globase/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e7ed4d73b80b6a7f220174cb7160b17884fec35
|
4
|
+
data.tar.gz: b89f7888dc1fe81d24dcc4531e425a5a1a17419a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e24f9e2d7e0c0700033ede03c91a057b85bf8b698258b79ef50bd7964cd6a5bb07b57b70ae1b9a7b8b15f357ca5dad31d5f118bb1e976e3146d9372e56ad757
|
7
|
+
data.tar.gz: 8bfc68992ca0bebd2618bf02e66f118d0e13c6921e915e24e18b58de8ae33cd70ec5cbc6736366cc21b91572fad6a8a27fc803a6ffa65aa6e25cafa75da16a87
|
data/Find Results
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
Searching 22 files for "send_request"
|
2
|
+
|
3
|
+
/Users/row/code/github/globase/lib/globase/list_schema.rb:
|
4
|
+
5
|
5
|
+
6 def get(parent, params = {})
|
6
|
+
7: send_request(parent, :get, params)
|
7
|
+
8
|
8
|
+
9 debug_response(response)
|
9
|
+
|
10
|
+
/Users/row/code/github/globase/lib/globase/nested_resource.rb:
|
11
|
+
25 end
|
12
|
+
26
|
13
|
+
27: def send_request(parent, method = :get, params = {}, id = nil, data = nil)
|
14
|
+
28 #begin
|
15
|
+
29 if id.nil?
|
16
|
+
|
17
|
+
/Users/row/code/github/globase/lib/globase/resource.rb:
|
18
|
+
15
|
19
|
+
16 def delete(params = {})
|
20
|
+
17: self.class.send_request(:delete, params, id)
|
21
|
+
18 end
|
22
|
+
19
|
23
|
+
..
|
24
|
+
22 update(params)
|
25
|
+
23 else
|
26
|
+
24: self.class.send_request(:post, params, nil, data)
|
27
|
+
25 persisted = true
|
28
|
+
26 end
|
29
|
+
..
|
30
|
+
29 def update(params = {})
|
31
|
+
30 if persisted
|
32
|
+
31: self.class.send_request(:put, params, id, data)
|
33
|
+
32 persisted = true
|
34
|
+
33 else
|
35
|
+
..
|
36
|
+
39
|
37
|
+
40 def find(id, params = {})
|
38
|
+
41: r = new( send_request(:get, params, id) )
|
39
|
+
42 r.persisted = true
|
40
|
+
43 r
|
41
|
+
..
|
42
|
+
45
|
43
|
+
46 def all(params = {})
|
44
|
+
47: send_request(:get, params).collect do |d|
|
45
|
+
48 r = new(d)
|
46
|
+
49 r.persisted = true
|
47
|
+
..
|
48
|
+
56 end
|
49
|
+
57
|
50
|
+
58: def send_request(method = :get, params = {}, id = nil, data = nil)
|
51
|
+
59 #begin
|
52
|
+
60 if id.nil?
|
53
|
+
|
54
|
+
8 matches across 3 files
|
55
|
+
|
56
|
+
|
57
|
+
Searching 22 files for "base_url"
|
58
|
+
|
59
|
+
/Users/row/code/github/globase/lib/globase/base.rb:
|
60
|
+
13
|
61
|
+
14 def url
|
62
|
+
15: "#{self.class.base_url}/#{id}"
|
63
|
+
16 end
|
64
|
+
17
|
65
|
+
..
|
66
|
+
70 end
|
67
|
+
71
|
68
|
+
72: def base_url(parent = nil)
|
69
|
+
73 "#{host_url}/#{collection_name}"
|
70
|
+
74 end
|
71
|
+
|
72
|
+
/Users/row/code/github/globase/lib/globase/nested_resource.rb:
|
73
|
+
13
|
74
|
+
14 def resource(parent, params = {})
|
75
|
+
15: @resource ||= RestClient::Resource.new( base_url( parent ), headers: headers(params), timeout: timeout )
|
76
|
+
16 end
|
77
|
+
17
|
78
|
+
18: def base_url(parent)
|
79
|
+
19 puts "Globase::NestedResource"
|
80
|
+
20 "#{parent.url}/#{collection_name}"
|
81
|
+
|
82
|
+
/Users/row/code/github/globase/lib/globase/resource.rb:
|
83
|
+
53
|
84
|
+
54 def resource(params = {})
|
85
|
+
55: @resource ||= RestClient::Resource.new( base_url, headers: headers(params), timeout: timeout )
|
86
|
+
56 end
|
87
|
+
57
|
88
|
+
|
89
|
+
5 matches across 3 files
|
data/Gemfile.lock
CHANGED
data/lib/globase.rb
CHANGED
@@ -4,9 +4,11 @@ require 'rest-client'
|
|
4
4
|
require 'active_support/inflector'
|
5
5
|
require 'active_support/core_ext/module/introspection'
|
6
6
|
require 'globase/configuration'
|
7
|
-
|
8
|
-
|
9
|
-
require
|
7
|
+
|
8
|
+
%w(base resource nested_resource list campaign list_profile list_schema list_segment ).each do |c|
|
9
|
+
require "globase/#{c}"
|
10
|
+
eval "Globase::#{c.camelcase}.set_fields"
|
11
|
+
end
|
10
12
|
|
11
13
|
module Globase
|
12
14
|
|
data/lib/globase/base.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
module Globase
|
2
|
+
class Base
|
3
|
+
format 'json'
|
4
|
+
|
5
|
+
attr_accessor :persisted
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
validation_errors = self.class.validate_data(:initialize, attributes)
|
9
|
+
if validation_errors.any?
|
10
|
+
validation_error_messages = validation_errors.join("\n - ")
|
11
|
+
raise "Validation errors:\n - #{validation_error_messages}"
|
12
|
+
end
|
13
|
+
|
14
|
+
attributes.each do |k,v|
|
15
|
+
send("#{ k }=", v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def url
|
20
|
+
"#{self.class.base_url}/#{id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def data
|
24
|
+
Hash[self.class.data_fields.collect{|a| [a, send(a) ]}]
|
25
|
+
end
|
26
|
+
|
27
|
+
def save(params = {})
|
28
|
+
if persisted
|
29
|
+
update(params)
|
30
|
+
else
|
31
|
+
create(data, params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
|
37
|
+
def fields
|
38
|
+
@fields = [:id]
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_fields
|
42
|
+
puts "set_fields: #{fields.inspect}"
|
43
|
+
fields.each do |a|
|
44
|
+
attr_accessor a
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_data(method, data)
|
49
|
+
errors = []
|
50
|
+
return errors if data.nil?
|
51
|
+
fields_data = data.keys
|
52
|
+
case method
|
53
|
+
when :put
|
54
|
+
fields_mandatory = fields_mandatory_update
|
55
|
+
when :post
|
56
|
+
fields_mandatory = fields_mandatory_create
|
57
|
+
when :initialize
|
58
|
+
fields_mandatory = fields_mandatory_initialize
|
59
|
+
end
|
60
|
+
|
61
|
+
fields_matching = fields_data & fields_mandatory
|
62
|
+
fileds_missing = fields_mandatory - fields_matching
|
63
|
+
|
64
|
+
errors << "Mandatory fields missing: #{fileds_missing.join(', ')}" if fileds_missing.any?
|
65
|
+
|
66
|
+
errors
|
67
|
+
end
|
68
|
+
|
69
|
+
def data_fields
|
70
|
+
fields - fields_ignore_for_data
|
71
|
+
end
|
72
|
+
|
73
|
+
def fields_ignore_for_data
|
74
|
+
[:parent]
|
75
|
+
end
|
76
|
+
|
77
|
+
def fields_mandatory_initialize
|
78
|
+
[]
|
79
|
+
end
|
80
|
+
|
81
|
+
def fields_mandatory_create
|
82
|
+
[]
|
83
|
+
end
|
84
|
+
|
85
|
+
def fields_mandatory_update
|
86
|
+
[:id]
|
87
|
+
end
|
88
|
+
|
89
|
+
def collection_name
|
90
|
+
self.name.demodulize.downcase.pluralize.downcase
|
91
|
+
end
|
92
|
+
|
93
|
+
def base_url(parent = nil)
|
94
|
+
"#{host_url}/#{collection_name}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse(body)
|
98
|
+
JSON.parse(body)
|
99
|
+
end
|
100
|
+
|
101
|
+
def timeout
|
102
|
+
Globase.config.timeout
|
103
|
+
end
|
104
|
+
|
105
|
+
def headers(params = {})
|
106
|
+
{
|
107
|
+
params: default_params.merge(params),
|
108
|
+
content_type: :json,
|
109
|
+
accept: :json,
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def default_params
|
114
|
+
{
|
115
|
+
api_key: Globase.config.api_key
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def host_url
|
120
|
+
"#{host_protocol}://#{host}:#{host_port}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def host
|
124
|
+
Globase.config.host
|
125
|
+
end
|
126
|
+
|
127
|
+
def host_port
|
128
|
+
Globase.config.host_port
|
129
|
+
end
|
130
|
+
|
131
|
+
def host_protocol
|
132
|
+
Globase.config.host_protocol
|
133
|
+
end
|
134
|
+
|
135
|
+
def debug_request(request_resource, method, params, data)
|
136
|
+
if Globase.config.debug
|
137
|
+
puts "#{'-'*80}"
|
138
|
+
puts " Resquest"
|
139
|
+
puts "#{'-'*80}"
|
140
|
+
puts " resource: #{request_resource}"
|
141
|
+
puts " method: #{method}"
|
142
|
+
puts " params: #{params.inspect}"
|
143
|
+
puts " data: #{data.inspect}"
|
144
|
+
puts " validation_errors: #{validate_data(method, data).inspect}"
|
145
|
+
puts "#{'-'*80}\n"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def debug_response(response)
|
150
|
+
if Globase.config.debug
|
151
|
+
puts "#{'*'*80}"
|
152
|
+
puts " Response"
|
153
|
+
puts "#{'*'*80}"
|
154
|
+
puts " code: #{response.code}"
|
155
|
+
puts " headers: #{response.headers.inspect}"
|
156
|
+
puts " body: #{response.body}"
|
157
|
+
puts "#{'*'*80}\n"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
data/lib/globase/campaign.rb
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
module Globase
|
2
2
|
class Campaign < Resource
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
def user=(value)
|
5
|
+
@ownerId = value
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(params = {})
|
9
|
+
super(params = {})
|
6
10
|
end
|
7
11
|
|
8
12
|
def delete(params = {})
|
9
13
|
raise NoMethodError
|
10
14
|
end
|
11
15
|
|
16
|
+
# send_request(method = :get, params = {}, relative_path = nil, data = nil)
|
17
|
+
|
18
|
+
def add_profile(list_profile, launchOptions = { data: nil }, params = {})
|
19
|
+
self.class.send_request(:post, params, "#{id}/addProfile/#{list_profile.id}", launchOptions)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_profiles(list_profile_ids, params = {})
|
23
|
+
self.class.send_request(:post, params, "#{id}/addProfiles", { profiles: list_profile_ids })
|
24
|
+
end
|
25
|
+
|
12
26
|
class << self
|
13
27
|
|
14
28
|
def create(data, params = {})
|
@@ -19,12 +33,16 @@ module Globase
|
|
19
33
|
super(params)
|
20
34
|
end
|
21
35
|
|
36
|
+
def fields
|
37
|
+
@fields = super | [:id, :list, :name, :type, :status, :sysCreated, :sysChanged, :ownerId, :ownerUsername, :ownerEmail, :spanCounts, :tags, :messages ]
|
38
|
+
end
|
39
|
+
|
22
40
|
def mandatory_fields_create
|
23
|
-
[:name, :list, :type]
|
41
|
+
[ :name, :list, :type, :status, :ownerId ]
|
24
42
|
end
|
25
43
|
|
26
44
|
def mandatory_fields_update
|
27
|
-
[:name, :list, :type]
|
45
|
+
[ :name, :list, :type, :status, :ownerId ]
|
28
46
|
end
|
29
47
|
|
30
48
|
end
|
data/lib/globase/list.rb
CHANGED
@@ -13,16 +13,36 @@ module Globase
|
|
13
13
|
raise NoMethodError
|
14
14
|
end
|
15
15
|
|
16
|
+
def profile(id, params = {})
|
17
|
+
ListProfile.find(self, id, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def schema(params = {})
|
21
|
+
@schema ||= ListSchema.get(self, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def segments(params = {})
|
25
|
+
@segments ||= ListSegment.all(self, params)
|
26
|
+
end
|
27
|
+
|
16
28
|
class << self
|
17
29
|
|
18
30
|
def create(data, params = {})
|
19
31
|
raise NoMethodError
|
20
32
|
end
|
21
33
|
|
34
|
+
def find(id, params = {})
|
35
|
+
all.select{|l| l.id == id.to_i }.first
|
36
|
+
end
|
37
|
+
|
22
38
|
def all(params = {})
|
23
39
|
super(params)
|
24
40
|
end
|
25
41
|
|
42
|
+
def fields
|
43
|
+
@fields = super | [:id, :name, :description, :profileCount, :sysCreated, :sysChanged]
|
44
|
+
end
|
45
|
+
|
26
46
|
end
|
27
47
|
|
28
48
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Globase
|
2
|
+
class ListProfile < NestedResource
|
3
|
+
|
4
|
+
def update(params = {})
|
5
|
+
if persisted
|
6
|
+
self.class.send_request(parent, :put, params, nil, data)
|
7
|
+
persisted = true
|
8
|
+
else
|
9
|
+
create(data, params = {})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def collection_name
|
16
|
+
:profile
|
17
|
+
end
|
18
|
+
|
19
|
+
def fields
|
20
|
+
@fields = super | [ :list, :sysCreated, :sysChanged, :optOutEmail, :optOutSms, :unConfirmed, :email, :company, :firstName, :lastName, :externalId ]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Globase
|
2
|
+
class ListSchema < NestedResource
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def get(parent, params = {})
|
7
|
+
data = send_request(parent, :get, params)
|
8
|
+
s = new( data.merge({ parent: parent }) )
|
9
|
+
s.persisted = true
|
10
|
+
s
|
11
|
+
end
|
12
|
+
|
13
|
+
def collection_name
|
14
|
+
:schema
|
15
|
+
end
|
16
|
+
|
17
|
+
def fields
|
18
|
+
@fields = super | ['Profile']
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Globase
|
2
|
+
class ListSegment < NestedResource
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def all(parent, params = {})
|
7
|
+
send_request(parent, :get, params).collect do |d|
|
8
|
+
r = new( d.merge({ parent: parent }) )
|
9
|
+
r.persisted = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def collection_name
|
14
|
+
:segments
|
15
|
+
end
|
16
|
+
|
17
|
+
def fields
|
18
|
+
@fields = super
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Globase
|
2
|
+
class NestedResource < Base
|
3
|
+
|
4
|
+
def reload
|
5
|
+
self.class.find(parent, id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete(params = {})
|
9
|
+
self.class.send_request(parent, :delete, params, id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(data, params = {})
|
13
|
+
if persisted
|
14
|
+
update(params)
|
15
|
+
else
|
16
|
+
response_data = self.class.send_request(parent, :post, params, nil, data)
|
17
|
+
id = response_data[:id]
|
18
|
+
persisted = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(params = {})
|
23
|
+
if persisted
|
24
|
+
self.class.send_request(parent, :put, params, id, data)
|
25
|
+
persisted = true
|
26
|
+
else
|
27
|
+
create(data, params = {})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
|
33
|
+
def find(parent, id, params = {})
|
34
|
+
data = send_request(parent, :get, params, id)
|
35
|
+
r = new( data.merge({ parent: parent }) )
|
36
|
+
if data.any?
|
37
|
+
r.persisted = true
|
38
|
+
else
|
39
|
+
return
|
40
|
+
end
|
41
|
+
r
|
42
|
+
end
|
43
|
+
|
44
|
+
def parent_resource_class
|
45
|
+
Globase::List
|
46
|
+
end
|
47
|
+
|
48
|
+
def fields_mandatory_initialize
|
49
|
+
[:parent]
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource(parent, params = {})
|
53
|
+
@resource ||= RestClient::Resource.new( base_url( parent ), headers: headers(params), timeout: timeout )
|
54
|
+
end
|
55
|
+
|
56
|
+
def base_url(parent)
|
57
|
+
puts "Globase::NestedResource"
|
58
|
+
"#{parent.url}/#{collection_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def fields
|
62
|
+
@fields = super | [:parent]
|
63
|
+
end
|
64
|
+
|
65
|
+
def send_request(parent, method = :get, params = {}, id = nil, data = nil)
|
66
|
+
#begin
|
67
|
+
if id.nil?
|
68
|
+
request_resource = resource(parent, params)["/"]
|
69
|
+
else
|
70
|
+
request_resource = resource(parent, params)["/#{id}"]
|
71
|
+
end
|
72
|
+
debug_request(request_resource, method, params, data)
|
73
|
+
|
74
|
+
if data.nil?
|
75
|
+
response = request_resource.send(method)
|
76
|
+
else
|
77
|
+
validation_errors = validate_data(method, data)
|
78
|
+
if validation_errors.empty?
|
79
|
+
response = request_resource.send(method, data.to_json)
|
80
|
+
else
|
81
|
+
validation_error_messages = validation_errors.join("\n - ")
|
82
|
+
raise "Validation errors:\n - #{validation_error_messages}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
debug_response(response)
|
87
|
+
parse(response.body)
|
88
|
+
#rescue => e
|
89
|
+
# if e.respond_to?(:response)
|
90
|
+
# e.response
|
91
|
+
# else
|
92
|
+
# raise e
|
93
|
+
# end
|
94
|
+
#end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/globase/resource.rb
CHANGED
@@ -1,109 +1,59 @@
|
|
1
1
|
module Globase
|
2
|
-
class Resource
|
3
|
-
format 'json'
|
2
|
+
class Resource < Base
|
4
3
|
|
5
|
-
def
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def id
|
10
|
-
@id
|
11
|
-
end
|
12
|
-
|
13
|
-
def show(params = {})
|
14
|
-
self.class.send_request(:get, params, id)
|
15
|
-
end
|
16
|
-
|
17
|
-
def update(data, params = {})
|
18
|
-
self.class.send_request(:put, params, id, data)
|
4
|
+
def reload
|
5
|
+
self.class.find(id)
|
19
6
|
end
|
20
7
|
|
21
8
|
def delete(params = {})
|
22
9
|
self.class.send_request(:delete, params, id)
|
23
10
|
end
|
24
11
|
|
25
|
-
def
|
26
|
-
|
12
|
+
def create(data, params = {})
|
13
|
+
if persisted
|
14
|
+
update(params)
|
15
|
+
else
|
16
|
+
response_data = self.class.send_request(:post, params, nil, data)
|
17
|
+
id = response_data[:id]
|
18
|
+
persisted = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(params = {})
|
23
|
+
if persisted
|
24
|
+
self.class.send_request(:put, params, id, data)
|
25
|
+
persisted = true
|
26
|
+
else
|
27
|
+
create(data, params = {})
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
class << self
|
30
32
|
|
31
|
-
def
|
32
|
-
send_request(:
|
33
|
+
def find(id, params = {})
|
34
|
+
r = new( send_request(:get, params, id) )
|
35
|
+
r.persisted = true
|
36
|
+
r
|
33
37
|
end
|
34
38
|
|
35
39
|
def all(params = {})
|
36
|
-
send_request(:get, params)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if Globase.config.debug
|
41
|
-
puts "\n#{'-'*80}"
|
42
|
-
puts " Resquest"
|
43
|
-
puts "#{'-'*80}"
|
44
|
-
puts " resource: #{request_resource}"
|
45
|
-
puts " method: #{method}"
|
46
|
-
puts " params: #{params.inspect}"
|
47
|
-
puts " data: #{data.inspect}"
|
48
|
-
puts " validation_errors: #{validate_data(method, data).inspect}"
|
49
|
-
puts "#{'-'*80}\n\n"
|
40
|
+
send_request(:get, params).collect do |d|
|
41
|
+
r = new(d)
|
42
|
+
r.persisted = true
|
43
|
+
r
|
50
44
|
end
|
51
45
|
end
|
52
46
|
|
53
|
-
def debug_response(response)
|
54
|
-
if Globase.config.debug
|
55
|
-
puts "\n#{'*'*80}"
|
56
|
-
puts " Response"
|
57
|
-
puts "#{'*'*80}"
|
58
|
-
puts " code: #{response.code}"
|
59
|
-
puts " headers: #{response.headers.inspect}"
|
60
|
-
puts " body: #{response.body}"
|
61
|
-
puts "#{'*'*80}\n\n"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
47
|
def resource(params = {})
|
66
48
|
@resource ||= RestClient::Resource.new( base_url, headers: headers(params), timeout: timeout )
|
67
49
|
end
|
68
50
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def validate_data(method, data)
|
75
|
-
errors = []
|
76
|
-
return errors if data.nil?
|
77
|
-
data_fields = data.keys
|
78
|
-
case method
|
79
|
-
when :put
|
80
|
-
mandatory_fields = mandatory_fields_update
|
81
|
-
when :post
|
82
|
-
mandatory_fields = mandatory_fields_create
|
83
|
-
end
|
84
|
-
|
85
|
-
matching_fields = data_fields & mandatory_fields
|
86
|
-
missing_fileds = mandatory_fields - matching_fields
|
87
|
-
|
88
|
-
errors << "Mandatory fields missing: #{missing_fileds.join(', ')}" if missing_fileds.any?
|
89
|
-
|
90
|
-
errors
|
91
|
-
end
|
92
|
-
|
93
|
-
def mandatory_fields_create
|
94
|
-
[]
|
95
|
-
end
|
96
|
-
|
97
|
-
def mandatory_fields_update
|
98
|
-
[]
|
99
|
-
end
|
100
|
-
|
101
|
-
def send_request(method = :get, params = {}, id = nil, data = nil)
|
102
|
-
begin
|
103
|
-
if id.nil?
|
51
|
+
def send_request(method = :get, params = {}, relative_path = nil, data = nil)
|
52
|
+
#begin
|
53
|
+
if relative_path.nil? || relative_path.to_s.strip.empty?
|
104
54
|
request_resource = resource(params)["/"]
|
105
55
|
else
|
106
|
-
request_resource = resource(params)["/#{
|
56
|
+
request_resource = resource(params)["/#{relative_path}"]
|
107
57
|
end
|
108
58
|
debug_request(request_resource, method, params, data)
|
109
59
|
|
@@ -121,60 +71,13 @@ module Globase
|
|
121
71
|
|
122
72
|
debug_response(response)
|
123
73
|
parse(response.body)
|
124
|
-
rescue => e
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def collection_name
|
134
|
-
self.name.demodulize.downcase.pluralize.downcase
|
135
|
-
end
|
136
|
-
|
137
|
-
def base_url
|
138
|
-
"#{host_url}/#{collection_name}"
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
def parse(body)
|
143
|
-
JSON.parse(body)
|
144
|
-
end
|
145
|
-
|
146
|
-
def timeout
|
147
|
-
Globase.config.timeout
|
148
|
-
end
|
149
|
-
|
150
|
-
def headers(params = {})
|
151
|
-
{
|
152
|
-
params: default_params.merge(params),
|
153
|
-
content_type: :json,
|
154
|
-
accept: :json,
|
155
|
-
}
|
156
|
-
end
|
157
|
-
|
158
|
-
def default_params
|
159
|
-
{
|
160
|
-
api_key: Globase.config.api_key
|
161
|
-
}
|
162
|
-
end
|
163
|
-
|
164
|
-
def host_url
|
165
|
-
"#{host_protocol}://#{host}:#{host_port}"
|
166
|
-
end
|
167
|
-
|
168
|
-
def host
|
169
|
-
Globase.config.host
|
170
|
-
end
|
171
|
-
|
172
|
-
def host_port
|
173
|
-
Globase.config.host_port
|
174
|
-
end
|
175
|
-
|
176
|
-
def host_protocol
|
177
|
-
Globase.config.host_protocol
|
74
|
+
#rescue => e
|
75
|
+
# if e.respond_to?(:response)
|
76
|
+
# e.response
|
77
|
+
# else
|
78
|
+
# raise e
|
79
|
+
# end
|
80
|
+
#end
|
178
81
|
end
|
179
82
|
|
180
83
|
end
|
data/lib/globase/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Wunderlin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -73,6 +73,7 @@ extensions: []
|
|
73
73
|
extra_rdoc_files:
|
74
74
|
- README.markdown
|
75
75
|
files:
|
76
|
+
- Find Results
|
76
77
|
- Gemfile
|
77
78
|
- Gemfile.lock
|
78
79
|
- LICENSE
|
@@ -80,9 +81,14 @@ files:
|
|
80
81
|
- Rakefile
|
81
82
|
- USAGE
|
82
83
|
- lib/globase.rb
|
84
|
+
- lib/globase/base.rb
|
83
85
|
- lib/globase/campaign.rb
|
84
86
|
- lib/globase/configuration.rb
|
85
87
|
- lib/globase/list.rb
|
88
|
+
- lib/globase/list_profile.rb
|
89
|
+
- lib/globase/list_schema.rb
|
90
|
+
- lib/globase/list_segment.rb
|
91
|
+
- lib/globase/nested_resource.rb
|
86
92
|
- lib/globase/resource.rb
|
87
93
|
- lib/globase/version.rb
|
88
94
|
homepage: http://www.rhg.dk
|