restly 0.0.1.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/restly/associations/base.rb +35 -0
- data/lib/restly/associations/belongs_to.rb +15 -0
- data/lib/restly/associations/builder.rb +30 -0
- data/lib/restly/associations/embeddable_resources/embeds_many.rb +7 -0
- data/lib/restly/associations/embeddable_resources/embeds_one.rb +7 -0
- data/lib/restly/associations/embeddable_resources.rb +28 -0
- data/lib/restly/associations/has_many.rb +23 -0
- data/lib/restly/associations/has_one.rb +23 -0
- data/lib/restly/associations.rb +90 -0
- data/lib/restly/base/fields.rb +79 -0
- data/lib/restly/base/generic_methods.rb +24 -0
- data/lib/restly/base/includes.rb +53 -0
- data/lib/restly/base/instance/actions.rb +35 -0
- data/lib/restly/base/instance/attributes.rb +88 -0
- data/lib/restly/base/instance/persistence.rb +20 -0
- data/lib/restly/base/instance.rb +76 -0
- data/lib/restly/base/mass_assignment_security.rb +19 -0
- data/lib/restly/base/resource/finders.rb +32 -0
- data/lib/restly/base/resource.rb +19 -0
- data/lib/restly/base/write_callbacks.rb +37 -0
- data/lib/restly/base.rb +82 -0
- data/lib/restly/client.rb +34 -0
- data/lib/restly/collection/pagination.rb +36 -0
- data/lib/restly/collection.rb +47 -0
- data/lib/restly/configuration.rb +43 -0
- data/lib/restly/connection.rb +99 -0
- data/lib/restly/controller_methods.rb +16 -0
- data/lib/restly/error.rb +30 -0
- data/lib/restly/middleware.rb +15 -0
- data/lib/restly/nested_attributes.rb +97 -0
- data/lib/restly/proxies/associations/collection.rb +22 -0
- data/lib/restly/proxies/associations/instance.rb +11 -0
- data/lib/restly/proxies/auth.rb +9 -0
- data/lib/restly/proxies/base.rb +39 -0
- data/lib/restly/proxies/params.rb +8 -0
- data/lib/restly/proxies.rb +18 -0
- data/lib/restly/railtie.rb +9 -0
- data/lib/restly/thread_local.rb +33 -0
- data/lib/restly/version.rb +3 -0
- data/lib/restly.rb +24 -0
- data/restly.gemspec +28 -0
- data/spec/fakewebs.rb +0 -0
- data/spec/helper.rb +31 -0
- data/spec/restly/base_spec.rb +60 -0
- metadata +210 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
class Restly::Proxies::Associations::Collection < Restly::Proxies::Base
|
2
|
+
|
3
|
+
attr_reader :parent, :joiner
|
4
|
+
|
5
|
+
def initialize(receiver, parent, joiner=nil)
|
6
|
+
super(receiver)
|
7
|
+
@parent = parent
|
8
|
+
@joiner = joiner
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(instance)
|
12
|
+
collection = receiver << instance
|
13
|
+
instance.save unless instance.persisted
|
14
|
+
if joiner
|
15
|
+
joiner.create("#{parent.resource_name}_id" => parent.id, "#{instance.resource_name}_id" => instance.id)
|
16
|
+
elsif parent
|
17
|
+
instance.update_attributes("#{parent.resource_name}_id" => parent.id)
|
18
|
+
end
|
19
|
+
collection
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Restly::Proxies::Base < SimpleDelegator
|
2
|
+
|
3
|
+
# Initialize the Proxy
|
4
|
+
def initialize(receiver)
|
5
|
+
|
6
|
+
# Dupe the Requester
|
7
|
+
if receiver.class == Class
|
8
|
+
@receiver = receiver.dup
|
9
|
+
|
10
|
+
# Some Key Methods Added to the Duplicated Requester
|
11
|
+
@receiver.class_eval %{
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
super.gsub(/^(#<)?#<[a-z0-9]+:([a-z0-9]+)(>)?/i, '#<#{receiver.name}:\\2')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.inspect
|
18
|
+
super.gsub(/^#<[a-z0-9]+:.*/i, '#{receiver.name}')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.name
|
22
|
+
"#{receiver.name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
}
|
26
|
+
else
|
27
|
+
@receiver = receiver
|
28
|
+
end
|
29
|
+
|
30
|
+
# Initialize the Delegator
|
31
|
+
super(@receiver)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Tell the Proxy its Class!
|
35
|
+
def class
|
36
|
+
@receiver.class
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Restly::Proxies
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
|
4
|
+
autoload :Auth
|
5
|
+
autoload :AssociatedInstance
|
6
|
+
autoload :AssociatedCollection
|
7
|
+
autoload :Params
|
8
|
+
autoload :Base
|
9
|
+
|
10
|
+
module Associations
|
11
|
+
extend ActiveSupport::Autoload
|
12
|
+
|
13
|
+
autoload :Collection
|
14
|
+
autoload :Instance
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Restly::ThreadLocal
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def thread_local_accessor(*names)
|
6
|
+
names.each do |name|
|
7
|
+
class_variable_set :"@@#{name}", {}
|
8
|
+
|
9
|
+
define_thread_getter(name)
|
10
|
+
define_thread_setter(name)
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def define_thread_getter(name)
|
16
|
+
accessor = class_variable_get("@@#{name}")
|
17
|
+
define_singleton_method name do
|
18
|
+
thread_id = Thread.current.object_id
|
19
|
+
accessor[thread_id]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def define_thread_setter(name)
|
24
|
+
accessor = class_variable_get("@@#{name}")
|
25
|
+
define_singleton_method "#{name}=" do |val|
|
26
|
+
thread_id = Thread.current.object_id
|
27
|
+
finalizer = ->(id){ class_variable_get("@@#{name}").delete(id) }
|
28
|
+
ObjectSpace.define_finalizer Thread.current, finalizer unless accessor.has_key? thread_id
|
29
|
+
accessor[thread_id] = val
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/restly.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "restly/version"
|
3
|
+
require "oauth2"
|
4
|
+
|
5
|
+
module Restly
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Base
|
9
|
+
autoload :BaseProxy
|
10
|
+
autoload :Proxies
|
11
|
+
autoload :Configuration
|
12
|
+
autoload :Collection
|
13
|
+
autoload :ControllerMethods
|
14
|
+
autoload :Associations
|
15
|
+
autoload :NestedAttributes
|
16
|
+
autoload :Error
|
17
|
+
autoload :Connection
|
18
|
+
autoload :Middleware
|
19
|
+
autoload :ThreadLocal
|
20
|
+
autoload :Client
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'restly/railtie' if Object.const_defined?('Rails')
|
data/restly.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "restly"
|
8
|
+
gem.version = Restly::VERSION
|
9
|
+
gem.authors = ["Jason Waldrip"]
|
10
|
+
gem.email = ["jason@waldrip.net"]
|
11
|
+
gem.description = %q{ Allows your app to authenticate a resource with oauth}
|
12
|
+
gem.summary = %q{ Allows your app to authenticate a resource with oauth}
|
13
|
+
gem.homepage = "http://github.com/jwaldrip/restly"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency "oauth2"
|
20
|
+
gem.add_dependency "activesupport"
|
21
|
+
gem.add_dependency "activemodel"
|
22
|
+
gem.add_dependency "colorize"
|
23
|
+
|
24
|
+
gem.add_development_dependency "rspec"
|
25
|
+
gem.add_development_dependency "pry"
|
26
|
+
gem.add_development_dependency "fakeweb"
|
27
|
+
|
28
|
+
end
|
data/spec/fakewebs.rb
ADDED
File without changes
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'active_model'
|
6
|
+
#require 'addressable/uri'
|
7
|
+
require 'rspec'
|
8
|
+
require 'rspec/autorun'
|
9
|
+
require 'restly'
|
10
|
+
require 'fakeweb'
|
11
|
+
require 'fakewebs'
|
12
|
+
|
13
|
+
|
14
|
+
Restly::Configuration.load_config(
|
15
|
+
{
|
16
|
+
site: 'http://fakesi.te',
|
17
|
+
client_id: 'default_id',
|
18
|
+
client_secret: 'default_secret',
|
19
|
+
default_format: 'json',
|
20
|
+
cache: false,
|
21
|
+
cache_opts: {
|
22
|
+
expires_in: 3600
|
23
|
+
}
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
Faraday.default_adapter = :test
|
28
|
+
|
29
|
+
RSpec.configure do |conf|
|
30
|
+
include OAuth2
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "pry"
|
3
|
+
|
4
|
+
describe Restly::Base do
|
5
|
+
|
6
|
+
subject { BaseSample }
|
7
|
+
|
8
|
+
before do
|
9
|
+
class BaseSample < Restly::Base
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Object.send(:remove_const, :BaseSample)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Defaults" do
|
18
|
+
|
19
|
+
it "has the default generated resource_name" do
|
20
|
+
subject.resource_name.should == 'base_sample'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has an Oauth2 client" do
|
24
|
+
subject.client.is_a?(OAuth2::Client).should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "client has the default site" do
|
28
|
+
subject.client.site.should == Restly::Configuration.site
|
29
|
+
end
|
30
|
+
|
31
|
+
it "client has the default client id" do
|
32
|
+
subject.client.id.should == Restly::Configuration.client_id
|
33
|
+
end
|
34
|
+
|
35
|
+
it "client has the default client secret" do
|
36
|
+
subject.client.secret.should == Restly::Configuration.client_secret
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Inherited Default Overrides" do
|
42
|
+
|
43
|
+
it "inherited can set a custom site" do
|
44
|
+
subject.site = "http://example_b.com"
|
45
|
+
subject.client.site.should_not == Restly::Configuration.client_id
|
46
|
+
end
|
47
|
+
|
48
|
+
it "inherited can set a custom client_id" do
|
49
|
+
subject.client_id = "custom_id"
|
50
|
+
subject.client.id.should_not == Restly::Configuration.client_id
|
51
|
+
end
|
52
|
+
|
53
|
+
it "inherited can set a custom client_secret" do
|
54
|
+
subject.client_secret = "custom_secret"
|
55
|
+
subject.client.secret.should_not == Restly::Configuration.client_id
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha.1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Waldrip
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activemodel
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: colorize
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: ! ' Allows your app to authenticate a resource with oauth'
|
127
|
+
email:
|
128
|
+
- jason@waldrip.net
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/restly.rb
|
139
|
+
- lib/restly/associations.rb
|
140
|
+
- lib/restly/associations/base.rb
|
141
|
+
- lib/restly/associations/belongs_to.rb
|
142
|
+
- lib/restly/associations/builder.rb
|
143
|
+
- lib/restly/associations/embeddable_resources.rb
|
144
|
+
- lib/restly/associations/embeddable_resources/embeds_many.rb
|
145
|
+
- lib/restly/associations/embeddable_resources/embeds_one.rb
|
146
|
+
- lib/restly/associations/has_many.rb
|
147
|
+
- lib/restly/associations/has_one.rb
|
148
|
+
- lib/restly/base.rb
|
149
|
+
- lib/restly/base/fields.rb
|
150
|
+
- lib/restly/base/generic_methods.rb
|
151
|
+
- lib/restly/base/includes.rb
|
152
|
+
- lib/restly/base/instance.rb
|
153
|
+
- lib/restly/base/instance/actions.rb
|
154
|
+
- lib/restly/base/instance/attributes.rb
|
155
|
+
- lib/restly/base/instance/persistence.rb
|
156
|
+
- lib/restly/base/mass_assignment_security.rb
|
157
|
+
- lib/restly/base/resource.rb
|
158
|
+
- lib/restly/base/resource/finders.rb
|
159
|
+
- lib/restly/base/write_callbacks.rb
|
160
|
+
- lib/restly/client.rb
|
161
|
+
- lib/restly/collection.rb
|
162
|
+
- lib/restly/collection/pagination.rb
|
163
|
+
- lib/restly/configuration.rb
|
164
|
+
- lib/restly/connection.rb
|
165
|
+
- lib/restly/controller_methods.rb
|
166
|
+
- lib/restly/error.rb
|
167
|
+
- lib/restly/middleware.rb
|
168
|
+
- lib/restly/nested_attributes.rb
|
169
|
+
- lib/restly/proxies.rb
|
170
|
+
- lib/restly/proxies/associations/collection.rb
|
171
|
+
- lib/restly/proxies/associations/instance.rb
|
172
|
+
- lib/restly/proxies/auth.rb
|
173
|
+
- lib/restly/proxies/base.rb
|
174
|
+
- lib/restly/proxies/params.rb
|
175
|
+
- lib/restly/railtie.rb
|
176
|
+
- lib/restly/thread_local.rb
|
177
|
+
- lib/restly/version.rb
|
178
|
+
- restly.gemspec
|
179
|
+
- spec/fakewebs.rb
|
180
|
+
- spec/helper.rb
|
181
|
+
- spec/restly/base_spec.rb
|
182
|
+
homepage: http://github.com/jwaldrip/restly
|
183
|
+
licenses: []
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
none: false
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ! '>'
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: 1.3.1
|
200
|
+
requirements: []
|
201
|
+
rubyforge_project:
|
202
|
+
rubygems_version: 1.8.23
|
203
|
+
signing_key:
|
204
|
+
specification_version: 3
|
205
|
+
summary: Allows your app to authenticate a resource with oauth
|
206
|
+
test_files:
|
207
|
+
- spec/fakewebs.rb
|
208
|
+
- spec/helper.rb
|
209
|
+
- spec/restly/base_spec.rb
|
210
|
+
has_rdoc:
|