globase 0.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +50 -0
- data/LICENSE +22 -0
- data/README.markdown +22 -0
- data/Rakefile +14 -0
- data/USAGE +12 -0
- data/lib/globase.rb +29 -0
- data/lib/globase/campaign.rb +33 -0
- data/lib/globase/configuration.rb +39 -0
- data/lib/globase/list.rb +29 -0
- data/lib/globase/resource.rb +183 -0
- data/lib/globase/version.rb +3 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8945e6903f98cdf4245bc144f65ef0dbfaf7f35
|
4
|
+
data.tar.gz: 1e11cd0d3a1b4a2d0fcc6945c582329eb88911dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 895c0e75a6258f2f00d7c66581c195d94f790a3bb622a4dc5bc08dad4f9a5e2a3e3ec9173bf303c47592ad15018384f640733d9a2d4d71309fa9dfb74cb191b0
|
7
|
+
data.tar.gz: 51d9df02256a6e57744e09a6d9e8b736a5ba2cdeb2bb3e306cc1798d79f4b5faad13db7636a348985a2ee7d8f495b709e741890d3a3a2a079c61bf6caa0382d9
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
globase (0.0.0.pre2)
|
5
|
+
activesupport
|
6
|
+
oj (>= 2.14.0)
|
7
|
+
oj_mimic_json
|
8
|
+
rest-client
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.2.6)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
domain_name (0.5.20160310)
|
20
|
+
unf (>= 0.0.5, < 1.0.0)
|
21
|
+
http-cookie (1.0.2)
|
22
|
+
domain_name (~> 0.5)
|
23
|
+
i18n (0.7.0)
|
24
|
+
json (1.8.3)
|
25
|
+
mime-types (2.99.2)
|
26
|
+
minitest (5.9.0)
|
27
|
+
netrc (0.11.0)
|
28
|
+
oj (2.15.1)
|
29
|
+
oj_mimic_json (1.0.1)
|
30
|
+
rake (10.4.2)
|
31
|
+
rest-client (1.8.0)
|
32
|
+
http-cookie (>= 1.0.2, < 2.0)
|
33
|
+
mime-types (>= 1.16, < 3.0)
|
34
|
+
netrc (~> 0.7)
|
35
|
+
thread_safe (0.3.5)
|
36
|
+
tzinfo (1.2.2)
|
37
|
+
thread_safe (~> 0.1)
|
38
|
+
unf (0.1.4)
|
39
|
+
unf_ext
|
40
|
+
unf_ext (0.0.7.2)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
globase!
|
47
|
+
rake
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
1.12.5
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 RelationshusetGekko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Globase
|
2
|
+
=========
|
3
|
+
Interface to the Globase API
|
4
|
+
|
5
|
+
3 steps install
|
6
|
+
===============
|
7
|
+
1. Add this in your Gemfile:
|
8
|
+
|
9
|
+
gem 'globase'
|
10
|
+
|
11
|
+
2. Run
|
12
|
+
|
13
|
+
rails generate globase:install
|
14
|
+
|
15
|
+
3. There is no 3
|
16
|
+
You are ready to go!
|
17
|
+
|
18
|
+
|
19
|
+
How does it work.
|
20
|
+
================
|
21
|
+
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#!/usr/bin/env rake
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'bundler/gem_tasks'
|
7
|
+
rescue LoadError
|
8
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
# APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
14
|
+
# load 'rails/tasks/engine.rake'
|
data/USAGE
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
************************************************************
|
2
|
+
|
3
|
+
Thank you for installing Globase
|
4
|
+
|
5
|
+
Once you have installed this gem
|
6
|
+
include it into your app Gemfile with:
|
7
|
+
gem 'globase'
|
8
|
+
|
9
|
+
Then from your app root type:
|
10
|
+
rails generate globase:install
|
11
|
+
|
12
|
+
************************************************************
|
data/lib/globase.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'oj'
|
2
|
+
require 'oj_mimic_json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
require 'active_support/core_ext/module/introspection'
|
6
|
+
require 'globase/configuration'
|
7
|
+
require 'globase/resource'
|
8
|
+
require 'globase/list'
|
9
|
+
require 'globase/campaign'
|
10
|
+
|
11
|
+
module Globase
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
# Accessor for Adminsite::Configuration
|
20
|
+
def configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
alias :config :configuration
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
Globase.config.log_file_path = 'globase.log' if Globase.config.debug
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Globase
|
2
|
+
class Campaign < Resource
|
3
|
+
|
4
|
+
def update(data, params = {})
|
5
|
+
super(data, params = {})
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete(params = {})
|
9
|
+
raise NoMethodError
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def create(data, params = {})
|
15
|
+
super(data, params = {})
|
16
|
+
end
|
17
|
+
|
18
|
+
def all(params = {})
|
19
|
+
super(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def mandatory_fields_create
|
23
|
+
[:name, :list, :type]
|
24
|
+
end
|
25
|
+
|
26
|
+
def mandatory_fields_update
|
27
|
+
[:name, :list, :type]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Globase
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
attr_accessor :api_key
|
6
|
+
attr_reader :timeout
|
7
|
+
|
8
|
+
attr_accessor :debug
|
9
|
+
|
10
|
+
attr_accessor :host
|
11
|
+
attr_accessor :host_port
|
12
|
+
attr_accessor :host_protocol
|
13
|
+
|
14
|
+
attr_reader :log_file_path
|
15
|
+
|
16
|
+
|
17
|
+
def log_file_path=(value)
|
18
|
+
@log_file_path = value
|
19
|
+
if value.nil?
|
20
|
+
RestClient.log = value
|
21
|
+
else
|
22
|
+
RestClient.log = Logger.new(value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Configuration defaults
|
27
|
+
def initialize
|
28
|
+
@api_key = nil
|
29
|
+
@timeout = 30
|
30
|
+
@debug = true
|
31
|
+
@host = 'rest.globase.com'
|
32
|
+
@host_port = 443
|
33
|
+
@host_protocol = 'https'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
data/lib/globase/list.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Globase
|
2
|
+
class List < Resource
|
3
|
+
|
4
|
+
def show(params = {})
|
5
|
+
raise NoMethodError
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(data, params = {})
|
9
|
+
raise NoMethodError
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(params = {})
|
13
|
+
raise NoMethodError
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def create(data, params = {})
|
19
|
+
raise NoMethodError
|
20
|
+
end
|
21
|
+
|
22
|
+
def all(params = {})
|
23
|
+
super(params)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module Globase
|
2
|
+
class Resource
|
3
|
+
format 'json'
|
4
|
+
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
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)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(params = {})
|
22
|
+
self.class.send_request(:delete, params, id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
"#{self.class.base_url}/#{id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
def create(data, params = {})
|
32
|
+
send_request(:post, params, nil, data)
|
33
|
+
end
|
34
|
+
|
35
|
+
def all(params = {})
|
36
|
+
send_request(:get, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def debug_request(request_resource, method, params, data)
|
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"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
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
|
+
def resource(params = {})
|
66
|
+
@resource ||= RestClient::Resource.new( base_url, headers: headers(params), timeout: timeout )
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def url
|
71
|
+
"#{base_url}/"
|
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?
|
104
|
+
request_resource = resource(params)["/"]
|
105
|
+
else
|
106
|
+
request_resource = resource(params)["/#{id}"]
|
107
|
+
end
|
108
|
+
debug_request(request_resource, method, params, data)
|
109
|
+
|
110
|
+
if data.nil?
|
111
|
+
response = request_resource.send(method)
|
112
|
+
else
|
113
|
+
validation_errors = validate_data(method, data)
|
114
|
+
if validation_errors.empty?
|
115
|
+
response = request_resource.send(method, data.to_json)
|
116
|
+
else
|
117
|
+
validation_error_messages = validation_errors.join("\n - ")
|
118
|
+
raise "Validation errors:\n - #{validation_error_messages}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
debug_response(response)
|
123
|
+
parse(response.body)
|
124
|
+
rescue => e
|
125
|
+
if e.respond_to?(:response)
|
126
|
+
e.response
|
127
|
+
else
|
128
|
+
raise e
|
129
|
+
end
|
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
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: globase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.pre2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Wunderlin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: oj_mimic_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Interface to the Globase API
|
70
|
+
email: robin@wunderlin.dk
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.markdown
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- LICENSE
|
79
|
+
- README.markdown
|
80
|
+
- Rakefile
|
81
|
+
- USAGE
|
82
|
+
- lib/globase.rb
|
83
|
+
- lib/globase/campaign.rb
|
84
|
+
- lib/globase/configuration.rb
|
85
|
+
- lib/globase/list.rb
|
86
|
+
- lib/globase/resource.rb
|
87
|
+
- lib/globase/version.rb
|
88
|
+
homepage: http://www.rhg.dk
|
89
|
+
licenses: []
|
90
|
+
metadata: {}
|
91
|
+
post_install_message: |-
|
92
|
+
************************************************************
|
93
|
+
|
94
|
+
Thank you for installing Globase
|
95
|
+
|
96
|
+
Once you have installed this gem
|
97
|
+
include it into your app Gemfile with:
|
98
|
+
gem 'globase'
|
99
|
+
|
100
|
+
Then from your app root type:
|
101
|
+
rails generate globase:install
|
102
|
+
|
103
|
+
************************************************************
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 2.1.9
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.3.1
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Interface to the Globase API
|
123
|
+
test_files: []
|