oare 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_resource_override/base.rb +67 -25
- data/oare.gemspec +1 -1
- metadata +2 -2
@@ -1,26 +1,76 @@
|
|
1
1
|
module Oare
|
2
2
|
module Resource
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:include, InstanceMethods)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
base.set_default_values
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def initialize(attributes = {})
|
12
|
+
self.class.instance_variable_get(:@nested_attributes).each do |key, value|
|
13
|
+
collection = attributes.delete(key)
|
14
|
+
next unless collection
|
15
|
+
attributes[value] = collection.map {|i, a| a}
|
16
|
+
end
|
17
|
+
super
|
10
18
|
end
|
11
19
|
end
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
module ClassMethods
|
22
|
+
attr_accessor :access_token
|
23
|
+
attr_accessor :associations
|
24
|
+
attr_accessor :nested_attributes
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
def set_default_values
|
27
|
+
self.nested_attributes ||= {}
|
28
|
+
self.associations ||= []
|
29
|
+
end
|
22
30
|
|
23
|
-
|
31
|
+
def has_many(association_id, options = {})
|
32
|
+
class_name = options[:class_name] || association_id.to_s.singularize.camelize
|
33
|
+
associations << class_name.constantize
|
34
|
+
|
35
|
+
define_method(association_id) do |*args|
|
36
|
+
resource = find_or_create_resource_for_collection(class_name)
|
37
|
+
if self.new_record? then [resource.new]
|
38
|
+
else
|
39
|
+
# TODO:
|
40
|
+
# Request for users of account
|
41
|
+
# Use an instance variable version of the access token
|
42
|
+
#
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def accepts_nested_attributes_for(association_id, options = {})
|
48
|
+
nested_attributes["#{association_id}_attributes"] = association_id
|
49
|
+
define_method("#{association_id}_attributes=") do |*args|
|
50
|
+
# TODO
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def access_token=(token)
|
55
|
+
@access_token = token
|
56
|
+
self.site = token.consumer.site
|
57
|
+
end
|
58
|
+
|
59
|
+
def connection(refresh = true)
|
60
|
+
self.access_token ? self.oauth_connection : super
|
61
|
+
end
|
62
|
+
|
63
|
+
def oauth_connection(refresh = true)
|
64
|
+
associations.each do |model_constant|
|
65
|
+
model_constant.access_token = self.access_token
|
66
|
+
end if associations
|
67
|
+
|
68
|
+
@connection = Oare::Connection.new(self.access_token) if @connection.nil? || refresh
|
69
|
+
@connection.timeout = timeout if timeout
|
70
|
+
@connection
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end # Oare Resource
|
24
74
|
|
25
75
|
module Gateway
|
26
76
|
|
@@ -59,12 +109,10 @@ class ActiveResource::Base
|
|
59
109
|
cattr_accessor :oauth_enabled_classes
|
60
110
|
|
61
111
|
class << self
|
62
|
-
attr_accessor :access_token
|
63
|
-
|
64
112
|
def requires_oauth
|
65
113
|
# Extend ActiveResource with this Module
|
66
114
|
#
|
67
|
-
|
115
|
+
include Oare::Resource
|
68
116
|
self.oauth_enabled_classes ||= {}
|
69
117
|
class_name = self.to_s.split('::')
|
70
118
|
key = class_name[-1].underscore.to_sym
|
@@ -72,12 +120,6 @@ class ActiveResource::Base
|
|
72
120
|
self.oauth_enabled_classes.merge!(key => class_name)
|
73
121
|
end
|
74
122
|
end
|
75
|
-
|
76
|
-
def access_token=(token)
|
77
|
-
@access_token = token
|
78
|
-
self.site = token.consumer.site
|
79
|
-
end
|
80
|
-
|
81
123
|
end
|
82
124
|
end
|
83
125
|
|
data/oare.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: oare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nelvin Driz
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-05-
|
14
|
+
date: 2011-05-18 00:00:00 +08:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|