resto 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/blankslate.rb +110 -0
- data/lib/resto.rb +264 -0
- data/lib/resto/attributes.rb +56 -0
- data/lib/resto/extra/copy.rb +34 -0
- data/lib/resto/extra/delegation.rb +26 -0
- data/lib/resto/extra/hash_args.rb +56 -0
- data/lib/resto/format.rb +20 -0
- data/lib/resto/format/default.rb +11 -0
- data/lib/resto/format/json.rb +30 -0
- data/lib/resto/format/plain.rb +14 -0
- data/lib/resto/format/xml.rb +66 -0
- data/lib/resto/property.rb +50 -0
- data/lib/resto/property/handler.rb +57 -0
- data/lib/resto/property/integer.rb +29 -0
- data/lib/resto/property/string.rb +19 -0
- data/lib/resto/property/time.rb +43 -0
- data/lib/resto/request/base.rb +88 -0
- data/lib/resto/request/factory.rb +66 -0
- data/lib/resto/request/header.rb +58 -0
- data/lib/resto/request/option.rb +126 -0
- data/lib/resto/request/uri.rb +50 -0
- data/lib/resto/response/base.rb +85 -0
- data/lib/resto/translator/request_factory.rb +44 -0
- data/lib/resto/translator/response_factory.rb +28 -0
- data/lib/resto/validate.rb +37 -0
- data/lib/resto/validate/inclusion.rb +39 -0
- data/lib/resto/validate/length.rb +36 -0
- data/lib/resto/validate/presence.rb +24 -0
- data/lib/resto/version.rb +5 -0
- data/resto.gemspec +43 -0
- data/spec/resto/extra/copy_spec.rb +58 -0
- data/spec/resto/extra/hash_args_spec.rb +71 -0
- data/spec/resto/format/default_spec.rb +24 -0
- data/spec/resto/format/json_spec.rb +29 -0
- data/spec/resto/format/plain_spec.rb +21 -0
- data/spec/resto/format/xml_spec.rb +105 -0
- data/spec/resto/property/handler_spec.rb +57 -0
- data/spec/resto/property/integer_spec.rb +67 -0
- data/spec/resto/property/time_spec.rb +124 -0
- data/spec/resto/property_spec.rb +60 -0
- data/spec/resto/request/base_spec.rb +253 -0
- data/spec/resto/request/factory_spec.rb +114 -0
- data/spec/resto/translator/response_factory_spec.rb +93 -0
- data/spec/resto/validate/presence_spec.rb +102 -0
- data/spec/resto_spec.rb +531 -0
- data/spec/spec_helper.rb +119 -0
- metadata +48 -3
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler/setup"
|
6
|
+
require "rspec"
|
7
|
+
require 'resto'
|
8
|
+
require 'webmock/rspec'
|
9
|
+
require 'yajl'
|
10
|
+
require 'time'
|
11
|
+
|
12
|
+
Bundler.require :default
|
13
|
+
|
14
|
+
RSpec.configure do |c|
|
15
|
+
c.mock_with :rspec
|
16
|
+
c.include WebMock::API
|
17
|
+
c.fail_fast = true
|
18
|
+
end
|
19
|
+
|
20
|
+
# Helper methods
|
21
|
+
def basic_encode(account, password)
|
22
|
+
'Basic ' + ["#{account}:#{password}"].pack('m').delete("\r\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
def headers(options = {})
|
26
|
+
{'accept' => '*/*', 'user-agent' => 'Ruby'}.merge(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def eval_context(string, &block)
|
30
|
+
eval(string)
|
31
|
+
context(string, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def class_context(klass, &block)
|
35
|
+
eval_context(klass, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_json(hash)
|
39
|
+
Yajl::Encoder.encode(hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
class Hash
|
43
|
+
def to_json
|
44
|
+
Yajl::Encoder.encode(self)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Array
|
49
|
+
def to_json
|
50
|
+
Yajl::Encoder.encode(self)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Copied from https://github.com/notahat/time_travel
|
55
|
+
module TimeTravel
|
56
|
+
module TimeExtensions
|
57
|
+
|
58
|
+
def self.included(base)
|
59
|
+
base.extend(ClassMethods)
|
60
|
+
base.class_eval do
|
61
|
+
class << self
|
62
|
+
alias_method :immutable_now, :now
|
63
|
+
alias_method :now, :mutable_now
|
64
|
+
end
|
65
|
+
end
|
66
|
+
base.now = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
module ClassMethods
|
70
|
+
|
71
|
+
@@now = nil
|
72
|
+
@@simulated_offset = nil
|
73
|
+
|
74
|
+
def now=(value)
|
75
|
+
@@now = value.is_a?(String) ? parse(value) : value
|
76
|
+
end
|
77
|
+
|
78
|
+
def mutable_now
|
79
|
+
@@now || immutable_now
|
80
|
+
end
|
81
|
+
|
82
|
+
def simulated_offset=(offset)
|
83
|
+
@@simulated_offset = offset
|
84
|
+
end
|
85
|
+
|
86
|
+
def simulated_offset
|
87
|
+
@@simulated_offset
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Time
|
95
|
+
include TimeTravel::TimeExtensions
|
96
|
+
|
97
|
+
def new_local_time
|
98
|
+
if self.class.simulated_offset
|
99
|
+
old_localtime(self.class.simulated_offset)
|
100
|
+
else
|
101
|
+
old_localtime
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
alias_method :old_localtime, :localtime
|
106
|
+
alias_method :localtime, :new_local_time
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def at_time(time, offset=nil)
|
111
|
+
Time.simulated_offset = offset
|
112
|
+
Time.now = time
|
113
|
+
begin
|
114
|
+
yield Time.now
|
115
|
+
ensure
|
116
|
+
Time.now = nil
|
117
|
+
Time.simulated_offset = nil
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: resto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Anders T\xC3\xB6rnqvist"
|
@@ -142,8 +142,53 @@ extensions: []
|
|
142
142
|
|
143
143
|
extra_rdoc_files: []
|
144
144
|
|
145
|
-
files:
|
146
|
-
|
145
|
+
files:
|
146
|
+
- lib/blankslate.rb
|
147
|
+
- lib/resto/attributes.rb
|
148
|
+
- lib/resto/extra/copy.rb
|
149
|
+
- lib/resto/extra/delegation.rb
|
150
|
+
- lib/resto/extra/hash_args.rb
|
151
|
+
- lib/resto/format/default.rb
|
152
|
+
- lib/resto/format/json.rb
|
153
|
+
- lib/resto/format/plain.rb
|
154
|
+
- lib/resto/format/xml.rb
|
155
|
+
- lib/resto/format.rb
|
156
|
+
- lib/resto/property/handler.rb
|
157
|
+
- lib/resto/property/integer.rb
|
158
|
+
- lib/resto/property/string.rb
|
159
|
+
- lib/resto/property/time.rb
|
160
|
+
- lib/resto/property.rb
|
161
|
+
- lib/resto/request/base.rb
|
162
|
+
- lib/resto/request/factory.rb
|
163
|
+
- lib/resto/request/header.rb
|
164
|
+
- lib/resto/request/option.rb
|
165
|
+
- lib/resto/request/uri.rb
|
166
|
+
- lib/resto/response/base.rb
|
167
|
+
- lib/resto/translator/request_factory.rb
|
168
|
+
- lib/resto/translator/response_factory.rb
|
169
|
+
- lib/resto/validate/inclusion.rb
|
170
|
+
- lib/resto/validate/length.rb
|
171
|
+
- lib/resto/validate/presence.rb
|
172
|
+
- lib/resto/validate.rb
|
173
|
+
- lib/resto/version.rb
|
174
|
+
- lib/resto.rb
|
175
|
+
- spec/resto/extra/copy_spec.rb
|
176
|
+
- spec/resto/extra/hash_args_spec.rb
|
177
|
+
- spec/resto/format/default_spec.rb
|
178
|
+
- spec/resto/format/json_spec.rb
|
179
|
+
- spec/resto/format/plain_spec.rb
|
180
|
+
- spec/resto/format/xml_spec.rb
|
181
|
+
- spec/resto/property/handler_spec.rb
|
182
|
+
- spec/resto/property/integer_spec.rb
|
183
|
+
- spec/resto/property/time_spec.rb
|
184
|
+
- spec/resto/property_spec.rb
|
185
|
+
- spec/resto/request/base_spec.rb
|
186
|
+
- spec/resto/request/factory_spec.rb
|
187
|
+
- spec/resto/translator/response_factory_spec.rb
|
188
|
+
- spec/resto/validate/presence_spec.rb
|
189
|
+
- spec/resto_spec.rb
|
190
|
+
- spec/spec_helper.rb
|
191
|
+
- resto.gemspec
|
147
192
|
homepage: http://rubygems.org/gems/resto
|
148
193
|
licenses: []
|
149
194
|
|