logical_model 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/Gemfile.lock +6 -6
- data/VERSION +1 -1
- data/lib/logical_model.rb +4 -4
- data/lib/ssl_support.rb +39 -0
- data/logical_model.gemspec +12 -11
- data/spec/client_spec.rb +2 -2
- data/test/typhoeus_mocks.rb +2 -1
- metadata +10 -9
data/Gemfile
CHANGED
@@ -3,14 +3,14 @@ source "http://rubygems.org"
|
|
3
3
|
|
4
4
|
gem "activemodel"
|
5
5
|
gem "activesupport"
|
6
|
-
gem "typhoeus", '0.5.
|
7
|
-
gem "ethon", "0.
|
6
|
+
gem "typhoeus", '0.5.3'
|
7
|
+
gem "ethon", "0.5.3"
|
8
8
|
gem "kaminari", '~> 0.13.0'
|
9
9
|
|
10
10
|
group :development, :test do
|
11
11
|
gem 'activerecord'
|
12
12
|
gem "shoulda"
|
13
|
-
gem "bundler", "~> 1.
|
13
|
+
gem "bundler", "~> 1.2.2"
|
14
14
|
gem "jeweler", "~> 1.6.4"
|
15
15
|
gem "rcov"
|
16
16
|
gem "sqlite3-ruby"
|
data/Gemfile.lock
CHANGED
@@ -27,7 +27,7 @@ GEM
|
|
27
27
|
builder (3.0.0)
|
28
28
|
diff-lcs (1.1.3)
|
29
29
|
erubis (2.7.0)
|
30
|
-
ethon (0.
|
30
|
+
ethon (0.5.3)
|
31
31
|
ffi (~> 1.0.11)
|
32
32
|
mime-types (~> 1.18)
|
33
33
|
ffi (1.0.11)
|
@@ -100,8 +100,8 @@ GEM
|
|
100
100
|
sqlite3 (>= 1.3.3)
|
101
101
|
thor (0.14.6)
|
102
102
|
tilt (1.3.3)
|
103
|
-
typhoeus (0.5.
|
104
|
-
ethon (~> 0.
|
103
|
+
typhoeus (0.5.3)
|
104
|
+
ethon (~> 0.5.3)
|
105
105
|
tzinfo (0.3.31)
|
106
106
|
|
107
107
|
PLATFORMS
|
@@ -111,8 +111,8 @@ DEPENDENCIES
|
|
111
111
|
activemodel
|
112
112
|
activerecord
|
113
113
|
activesupport
|
114
|
-
bundler (~> 1.
|
115
|
-
ethon (= 0.
|
114
|
+
bundler (~> 1.2.2)
|
115
|
+
ethon (= 0.5.3)
|
116
116
|
gemcutter
|
117
117
|
guard-rspec
|
118
118
|
jeweler (~> 1.6.4)
|
@@ -125,4 +125,4 @@ DEPENDENCIES
|
|
125
125
|
shoulda
|
126
126
|
sinatra (~> 1.2.6)
|
127
127
|
sqlite3-ruby
|
128
|
-
typhoeus (= 0.5.
|
128
|
+
typhoeus (= 0.5.3)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/logical_model.rb
CHANGED
@@ -4,6 +4,7 @@ require 'typhoeus'
|
|
4
4
|
require 'active_support/all' # todo migrate to yajl
|
5
5
|
require 'logger'
|
6
6
|
require 'kaminari'
|
7
|
+
require 'ssl_support'
|
7
8
|
require 'safe_log'
|
8
9
|
|
9
10
|
# Logical Model, not persistant on DB, works through API. (replaces ActiveResource)
|
@@ -42,6 +43,7 @@ require 'safe_log'
|
|
42
43
|
# RemoteResource#destroy
|
43
44
|
class LogicalModel
|
44
45
|
|
46
|
+
include SslSupport
|
45
47
|
extend SafeLog
|
46
48
|
|
47
49
|
# include ActiveModel Modules that are usefull
|
@@ -75,12 +77,11 @@ class LogicalModel
|
|
75
77
|
class << self
|
76
78
|
attr_accessor :host, :hydra, :resource_path, :api_key, :api_key_name,
|
77
79
|
:timeout, :retries,
|
78
|
-
:
|
80
|
+
:use_api_key, :enable_delete_multiple,
|
79
81
|
:json_root, :log_path
|
80
82
|
|
81
83
|
def timeout; @timeout ||= DEFAULT_TIMEOUT; end
|
82
84
|
def retries; @retries ||= DEFAULT_RETRIES; end
|
83
|
-
def use_ssl; @use_ssl ||= false; end
|
84
85
|
def log_path; @log_path ||= "log/logical_model.log"; end
|
85
86
|
def use_api_key; @use_api_key ||= false; end
|
86
87
|
def delete_multiple_enabled?; @enable_delete_multiple ||= false; end
|
@@ -106,9 +107,8 @@ class LogicalModel
|
|
106
107
|
end
|
107
108
|
|
108
109
|
def self.resource_uri(id=nil)
|
109
|
-
prefix = (use_ssl)? "https://" : "http://"
|
110
110
|
sufix = (id.nil?)? "" : "/#{id}"
|
111
|
-
"#{
|
111
|
+
"#{url_protocol_prefix}#{host}#{resource_path}#{sufix}"
|
112
112
|
end
|
113
113
|
|
114
114
|
def initialize(attributes={})
|
data/lib/ssl_support.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module SslSupport
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.class.send(:attr_accessor, :use_ssl)
|
5
|
+
base.send(:include, InstanceMethods)
|
6
|
+
base.send(:extend, ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
##
|
15
|
+
# Default use_ssl to ssl_recommend?
|
16
|
+
# @return [Boolean]
|
17
|
+
def use_ssl?
|
18
|
+
@use_ssl ||= ssl_recommended?
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
def url_protocol_prefix
|
23
|
+
(use_ssl?)? "https://" : "http://"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns true if ssl is recommended according to environment.
|
27
|
+
#
|
28
|
+
# - production, staging -> true
|
29
|
+
# - other -> false
|
30
|
+
#
|
31
|
+
# @return [Boolean]
|
32
|
+
def ssl_recommended?
|
33
|
+
ssl_recommended_environments = %W(production staging)
|
34
|
+
ssl_recommended_environments.include?(defined?(Rails)? Rails.env : ENV['RACK_ENV'] )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
data/logical_model.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "logical_model"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dwayne Macgowan"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-30"
|
13
13
|
s.description = "LogicalModel allows to use a resource as a model. It is based on web presentation http://www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3"
|
14
14
|
s.email = "dwaynemac@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"db/migrate/001_create_users.rb",
|
34
34
|
"lib/logical_model.rb",
|
35
35
|
"lib/safe_log.rb",
|
36
|
+
"lib/ssl_support.rb",
|
36
37
|
"lib/typhoeus_fix/array_decoder.rb",
|
37
38
|
"logical_model.gemspec",
|
38
39
|
"models/user.rb",
|
@@ -53,12 +54,12 @@ Gem::Specification.new do |s|
|
|
53
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
55
|
s.add_runtime_dependency(%q<activemodel>, [">= 0"])
|
55
56
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
56
|
-
s.add_runtime_dependency(%q<typhoeus>, ["= 0.5.
|
57
|
-
s.add_runtime_dependency(%q<ethon>, ["= 0.
|
57
|
+
s.add_runtime_dependency(%q<typhoeus>, ["= 0.5.3"])
|
58
|
+
s.add_runtime_dependency(%q<ethon>, ["= 0.5.3"])
|
58
59
|
s.add_runtime_dependency(%q<kaminari>, ["~> 0.13.0"])
|
59
60
|
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
60
61
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
61
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.2.2"])
|
62
63
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
64
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
64
65
|
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
@@ -72,12 +73,12 @@ Gem::Specification.new do |s|
|
|
72
73
|
else
|
73
74
|
s.add_dependency(%q<activemodel>, [">= 0"])
|
74
75
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
75
|
-
s.add_dependency(%q<typhoeus>, ["= 0.5.
|
76
|
-
s.add_dependency(%q<ethon>, ["= 0.
|
76
|
+
s.add_dependency(%q<typhoeus>, ["= 0.5.3"])
|
77
|
+
s.add_dependency(%q<ethon>, ["= 0.5.3"])
|
77
78
|
s.add_dependency(%q<kaminari>, ["~> 0.13.0"])
|
78
79
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
79
80
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
80
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
81
82
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
82
83
|
s.add_dependency(%q<rcov>, [">= 0"])
|
83
84
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
@@ -92,12 +93,12 @@ Gem::Specification.new do |s|
|
|
92
93
|
else
|
93
94
|
s.add_dependency(%q<activemodel>, [">= 0"])
|
94
95
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
95
|
-
s.add_dependency(%q<typhoeus>, ["= 0.5.
|
96
|
-
s.add_dependency(%q<ethon>, ["= 0.
|
96
|
+
s.add_dependency(%q<typhoeus>, ["= 0.5.3"])
|
97
|
+
s.add_dependency(%q<ethon>, ["= 0.5.3"])
|
97
98
|
s.add_dependency(%q<kaminari>, ["~> 0.13.0"])
|
98
99
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
99
100
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
100
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
101
|
+
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
101
102
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
102
103
|
s.add_dependency(%q<rcov>, [">= 0"])
|
103
104
|
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
data/spec/client_spec.rb
CHANGED
@@ -147,7 +147,7 @@ describe "LogicalModel User client" do
|
|
147
147
|
response = mock(
|
148
148
|
code: 200,
|
149
149
|
body: {}.to_json,
|
150
|
-
|
150
|
+
effective_url: "server?keyname=secret_api_key",
|
151
151
|
time: 1234
|
152
152
|
)
|
153
153
|
Logger.any_instance.should_receive(:info).with(/\[SECRET\]/)
|
@@ -192,7 +192,7 @@ describe "LogicalModel User client" do
|
|
192
192
|
|
193
193
|
describe "delete_multiple" do
|
194
194
|
before do
|
195
|
-
Typhoeus::Request.stub!(:delete).and_return(mock_response(body: 'ok'))
|
195
|
+
Typhoeus::Request.stub!(:delete).and_return(mock_response(body: 'ok', effective_url: 'mocked-url'))
|
196
196
|
end
|
197
197
|
context "when disabled" do
|
198
198
|
it "should raise exception" do
|
data/test/typhoeus_mocks.rb
CHANGED
@@ -15,7 +15,7 @@ module TyphoeusMocks
|
|
15
15
|
collection: options[:collection] || [],
|
16
16
|
total: options[:total] || 0
|
17
17
|
}.to_json,
|
18
|
-
|
18
|
+
effective_url: options[:url] || 'mockedurl',
|
19
19
|
time: 1234
|
20
20
|
)
|
21
21
|
req.stub(:on_complete).and_yield(response)
|
@@ -32,6 +32,7 @@ module TyphoeusMocks
|
|
32
32
|
response = mock(
|
33
33
|
code: options[:status] || 200,
|
34
34
|
body: options[:attributes].to_json,
|
35
|
+
effective_url: options[:url] || 'mockedurl',
|
35
36
|
request: mock(url: options[:url] || "mockedurl"),
|
36
37
|
time: 1234
|
37
38
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logical_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - '='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.5.
|
53
|
+
version: 0.5.3
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.5.
|
61
|
+
version: 0.5.3
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: ethon
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - '='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.5.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - '='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0.
|
77
|
+
version: 0.5.3
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: kaminari
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
133
|
+
version: 1.2.2
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -138,7 +138,7 @@ dependencies:
|
|
138
138
|
requirements:
|
139
139
|
- - ~>
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: 1.
|
141
|
+
version: 1.2.2
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: jeweler
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -324,6 +324,7 @@ files:
|
|
324
324
|
- db/migrate/001_create_users.rb
|
325
325
|
- lib/logical_model.rb
|
326
326
|
- lib/safe_log.rb
|
327
|
+
- lib/ssl_support.rb
|
327
328
|
- lib/typhoeus_fix/array_decoder.rb
|
328
329
|
- logical_model.gemspec
|
329
330
|
- models/user.rb
|
@@ -346,7 +347,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
346
347
|
version: '0'
|
347
348
|
segments:
|
348
349
|
- 0
|
349
|
-
hash:
|
350
|
+
hash: 474549263
|
350
351
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
352
|
none: false
|
352
353
|
requirements:
|