oa_test 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,8 @@ if arg.size>0
33
33
  :secret => cons[1],
34
34
  :return => (retrn ? retrn.split(':')[1].to_sym : :body),
35
35
  :host => (host ? host.split(':')[1,99].join(':') : nil),
36
- :api => (api ? api.split(':')[1]: nil)
36
+ :api => (api ? api.split(':')[1]: nil),
37
+ :file => __FILE__
37
38
  ).
38
39
  yauth(
39
40
  :login => yths[0].strip,
@@ -35,8 +35,9 @@ class OAuthTest
35
35
  @config.api = ks[:api] if ks[:api]
36
36
 
37
37
  @config.return = ks[:return] if ks[:return]
38
+ @config.file = ks[:file] if ks[:file]
38
39
 
39
- if ks[:key] || ks[:secret] || ks[:return] || ks[:host] || ks[:api]
40
+ if ks[:key] || ks[:secret] || ks[:return] || ks[:host] || ks[:api] || ks[:file]
40
41
  File.open(File.expand_path("~/.oa_test"),'w') { |f| f.puts @config.to_yaml }
41
42
  end
42
43
  end
@@ -12,10 +12,11 @@ class OAuthTest
12
12
  @secret = config.secret
13
13
  @return = config.return
14
14
  @host = config.host
15
- @api = config.api
15
+ @api = config.api
16
+ @irb = (config.file ? config.file=~/bin\/oa_test$/ : false)
16
17
  @typ = {
17
18
  :json => {"Accept" => "application/json", "Content-Type" => "application/json"},
18
- :xml => {"Accept" => "application/xml", "Content-Type" => "application/xml"},
19
+ :xml => {"Accept" => "application/xml", "Content-Type" => "application/xml"},
19
20
  }
20
21
  end
21
22
 
@@ -24,18 +25,22 @@ class OAuthTest
24
25
  end
25
26
 
26
27
  def get(path)
28
+ puts "GET #{@host+@api+path}" if @irb
27
29
  rtn @access_token.get(@host+@api+path,typ(path))
28
30
  end
29
31
 
30
32
  def post(path,params)
33
+ puts "POST #{@host+@api+path}, body:#{params.inspect}" if @irb
31
34
  rtn @access_token.post(@host+@api+path,params.to_json,typ(path))
32
35
  end
33
36
 
34
37
  def put(path,params)
38
+ puts "PUT #{@host+@api+path}, body:#{params.inspect}" if @irb
35
39
  rtn @access_token.put(@host+@api+path,params.to_json,typ(path))
36
40
  end
37
41
 
38
42
  def delete(path)
43
+ puts "DELETE #{@host+@api+path}" if @irb
39
44
  rtn @access_token.delete(@host+@api+path,typ(path))
40
45
  end
41
46
 
@@ -64,7 +69,7 @@ class OAuthTest
64
69
 
65
70
  def rtn(resp)
66
71
  @resp = resp
67
- puts resp.class
72
+ puts resp.class if @irb
68
73
  if @return==nil || resp.class!=Net::HTTPOK || @return==:body
69
74
  resp.body
70
75
  elsif @return==:body_hash && resp.class==Net::HTTPOK
@@ -1,3 +1,3 @@
1
1
  module OaTestVersion
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa_test
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Watchmen
@@ -92,7 +92,6 @@ extensions: []
92
92
  extra_rdoc_files: []
93
93
 
94
94
  files:
95
- - lib/oa_test/cattr.rb
96
95
  - lib/oa_test/from_jsonxml.rb
97
96
  - lib/oa_test/oa_config.rb
98
97
  - lib/oa_test/oa_test.rb
@@ -1,264 +0,0 @@
1
- class Module
2
-
3
- # Creates a class-variable attribute that can
4
- # be accessed both on an instance and class level.
5
- #
6
- # class CARExample
7
- # @@a = 10
8
- # cattr :a
9
- # end
10
- #
11
- # CARExample.a #=> 10
12
- # CARExample.new.a #=> 10
13
- #
14
- # NOTE: This is not (presently) a common core extension and is not
15
- # loaded automatically when using <code>require 'facets'</code>.
16
- #
17
- # CREDIT: David Heinemeier Hansson
18
- def cattr(*syms)
19
- writers, readers = syms.flatten.partition{ |a| a.to_s =~ /=$/ }
20
- writers = writers.map{ |e| e.to_s.chomp('=').to_sym }
21
- ##readers.concat( writers ) # writers also get readers
22
-
23
- cattr_reader(*readers)
24
- cattr_writer(*writers)
25
-
26
- return readers + writers
27
- end
28
-
29
- # Creates a class-variable attr_reader that can
30
- # be accessed both on an instance and class level.
31
- #
32
- # class CARExample
33
- # @@a = 10
34
- # cattr_reader :a
35
- # end
36
- #
37
- # CARExample.a #=> 10
38
- # CARExample.new.a #=> 10
39
- #
40
- # NOTE: This is not (presently) a common core extension and is not
41
- # loaded automatically when using <code>require 'facets'</code>.
42
- #
43
- # CREDIT: David Heinemeier Hansson
44
- def cattr_reader(*syms)
45
- syms.flatten.each do |sym|
46
- module_eval(<<-EOS, __FILE__, __LINE__)
47
- unless defined? @@#{sym}
48
- @@#{sym} = nil
49
- end
50
-
51
- def self.#{sym}
52
- @@#{sym}
53
- end
54
-
55
- def #{sym}
56
- @@#{sym}
57
- end
58
- EOS
59
- end
60
- return syms
61
- end
62
-
63
- # Creates a class-variable attr_writer that can
64
- # be accessed both on an instance and class level.
65
- #
66
- # class CAWExample
67
- # cattr_writer :a
68
- # def self.a
69
- # @@a
70
- # end
71
- # end
72
- #
73
- # CAWExample.a = 10
74
- # CAWExample.a #=> 10
75
- # CAWExample.new.a = 29
76
- # CAWExample.a #=> 29
77
- #
78
- # NOTE: This is not (presently) a common core extension and is not
79
- # loaded automatically when using <code>require 'facets'</code>.
80
- #
81
- # CREDIT: David Heinemeier Hansson
82
- def cattr_writer(*syms)
83
- syms.flatten.each do |sym|
84
- module_eval(<<-EOS, __FILE__, __LINE__)
85
- unless defined? @@#{sym}
86
- @@#{sym} = nil
87
- end
88
-
89
- def self.#{sym}=(obj)
90
- @@#{sym} = obj
91
- end
92
-
93
- def #{sym}=(obj)
94
- @@#{sym}=(obj)
95
- end
96
- EOS
97
- end
98
- return syms
99
- end
100
-
101
- # Creates a class-variable attr_accessor that can
102
- # be accessed both on an instance and class level.
103
- #
104
- # class CAAExample
105
- # cattr_accessor :a
106
- # end
107
- #
108
- # CAAExample.a = 10
109
- # CAAExample.a #=> 10
110
- # mc = CAAExample.new
111
- # mc.a #=> 10
112
- #
113
- # NOTE: This is not (presently) a common core extension and is not
114
- # loaded automatically when using <code>require 'facets'</code>.
115
- #
116
- # CREDIT: David Heinemeier Hansson
117
- def cattr_accessor(*syms)
118
- cattr_reader(*syms) + cattr_writer(*syms)
119
- end
120
-
121
- # Creates a class-variable attribute that can
122
- # be accessed both on an instance and class level.
123
- #
124
- # c = Class.new do
125
- # mattr :a
126
- # def initialize
127
- # @@a = 10
128
- # end
129
- # end
130
- #
131
- # c.new.a #=> 10
132
- # c.a #=> 10
133
- #
134
- # NOTE: The #mattr methods may not be as useful for modules as the #cattr
135
- # methods are for classes, becuase class-level methods are not "inherited"
136
- # across the metaclass for included modules.
137
- #
138
- # NOTE: This is not (presently) a common core extension and is not
139
- # loaded automatically when using <code>require 'facets'</code>.
140
- #
141
- # CREDIT: David Heinemeier Hansson
142
- def mattr(*syms)
143
- writers, readers = syms.flatten.partition{ |a| a.to_s =~ /=$/ }
144
- writers = writers.collect{ |e| e.to_s.chomp('=').to_sym }
145
- ##readers.concat( writers ) # writers also get readers
146
-
147
- mattr_writer( *writers )
148
- mattr_reader( *readers )
149
-
150
- return readers + writers
151
- end
152
-
153
- # Creates a class-variable attr_reader that can
154
- # be accessed both on an instance and class level.
155
- #
156
- # c = Class.new do
157
- # @@a = 10
158
- # mattr_reader :a
159
- # end
160
- #
161
- # c.a #=> 10
162
- # c.new.a #=> 10
163
- #
164
- # NOTE: This is not (presently) a common core extension and is not
165
- # loaded automatically when using <code>require 'facets'</code>.
166
- #
167
- # CREDIT: David Heinemeier Hansson
168
- def mattr_reader( *syms )
169
- syms.flatten.each do |sym|
170
- module_eval(<<-EOS, __FILE__, __LINE__)
171
- unless defined? @@#{sym}
172
- @@#{sym} = nil
173
- end
174
-
175
- def self.#{sym}
176
- @@#{sym}
177
- end
178
-
179
- def #{sym}
180
- @@#{sym}
181
- end
182
- EOS
183
- end
184
- return syms
185
- end
186
-
187
- # Creates a class-variable attr_writer that can
188
- # be accessed both on an instance and class level.
189
- #
190
- # c = Class.new do
191
- # mattr_writer :a
192
- # def self.a
193
- # @@a
194
- # end
195
- # end
196
- #
197
- # c.a = 10
198
- # c.a #=> 10
199
- #
200
- # c.new.a = 29
201
- # c.a #=> 29
202
- #
203
- # NOTE: This is not (presently) a common core extension and is not
204
- # loaded automatically when using <code>require 'facets'</code>.
205
- #
206
- # CREDIT: David Heinemeier Hansson
207
- def mattr_writer(*syms)
208
- syms.flatten.each do |sym|
209
- module_eval(<<-EOS, __FILE__, __LINE__)
210
- unless defined? @@#{sym}
211
- @@#{sym} = nil
212
- end
213
-
214
- def self.#{sym}=(obj)
215
- @@#{sym} = obj
216
- end
217
-
218
- def #{sym}=(obj)
219
- @@#{sym}=(obj)
220
- end
221
- EOS
222
- end
223
- return syms
224
- end
225
-
226
- # Creates a class-variable attr_accessor that can
227
- # be accessed both on an instance and class level.
228
- #
229
- # c = Class.new do
230
- # mattr_accessor :a
231
- # end
232
- #
233
- # c.a = 10
234
- # c.a #=> 10
235
- #
236
- # x = c.new
237
- # x.a #=> 10
238
- #
239
- # NOTE: This is not (presently) a common core extension and is not
240
- # loaded automatically when using <code>require 'facets'</code>.
241
- #
242
- # CREDIT: David Heinemeier Hansson
243
- def mattr_accessor(*syms)
244
- mattr_reader(*syms) + mattr_writer(*syms)
245
- end
246
-
247
- end
248
-
249
- # Consider the issue where a module's metaclass is not inherited.
250
- #
251
- # m = Module.new do
252
- # @@a = 10
253
- # mattr_reader :a
254
- # end
255
- #
256
- # c = Class.new do
257
- # include m
258
- # end
259
- #
260
- # expect NoMethodError do
261
- # c.a
262
- # end
263
- #
264
- # Ideally this would work.