kelredd-resourceful 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/resourceful/model/base.rb +13 -4
- data/lib/resourceful/version.rb +1 -1
- metadata +4 -13
- data/features/models.feature +0 -22
- data/features/rest_client.feature +0 -61
- data/features/step_definitions/model_steps.rb +0 -63
- data/features/step_definitions/rest_client_steps.rb +0 -84
- data/features/step_definitions/support/env.rb +0 -14
- data/features/step_definitions/support/helpers.rb +0 -13
- data/features/step_definitions/support/models.rb +0 -97
- data/test/test_helper.rb +0 -9
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ spec = Gem::Specification.new do |s|
|
|
16
16
|
s.author = 'Kelly Redding'
|
17
17
|
s.email = 'kelly@kelredd.com'
|
18
18
|
s.homepage = ''
|
19
|
-
s.files = %w(README.rdoc Rakefile) + Dir.glob("{
|
19
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
|
20
20
|
# s.executables = ['resourceful']
|
21
21
|
|
22
22
|
s.add_dependency('nokogiri')
|
@@ -4,15 +4,15 @@ module Resourceful
|
|
4
4
|
class Base
|
5
5
|
|
6
6
|
@@agent = nil
|
7
|
-
def self.agent(
|
8
|
-
@@agent =
|
7
|
+
def self.agent(&block)
|
8
|
+
@@agent = block;
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.get(path, opts={})
|
12
|
-
|
12
|
+
set_agent.get(path, opts)
|
13
13
|
end
|
14
14
|
def self.get_collection(path, opts={})
|
15
|
-
(yield
|
15
|
+
(yield set_agent.get(path, opts)).collect{|data| new(data)}
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(data)
|
@@ -97,6 +97,15 @@ module Resourceful
|
|
97
97
|
)
|
98
98
|
end
|
99
99
|
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def self.set_agent
|
104
|
+
unless @@agent.kind_of?(Resourceful::Agent::Base)
|
105
|
+
@@agent = @@agent.call
|
106
|
+
end
|
107
|
+
@@agent
|
108
|
+
end
|
100
109
|
|
101
110
|
end
|
102
111
|
|
data/lib/resourceful/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelredd-resourceful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -73,15 +73,6 @@ extra_rdoc_files:
|
|
73
73
|
files:
|
74
74
|
- README.rdoc
|
75
75
|
- Rakefile
|
76
|
-
- features/models.feature
|
77
|
-
- features/rest_client.feature
|
78
|
-
- features/step_definitions
|
79
|
-
- features/step_definitions/model_steps.rb
|
80
|
-
- features/step_definitions/rest_client_steps.rb
|
81
|
-
- features/step_definitions/support
|
82
|
-
- features/step_definitions/support/env.rb
|
83
|
-
- features/step_definitions/support/helpers.rb
|
84
|
-
- features/step_definitions/support/models.rb
|
85
76
|
- lib/resourceful
|
86
77
|
- lib/resourceful/agent
|
87
78
|
- lib/resourceful/agent/base.rb
|
@@ -100,9 +91,9 @@ files:
|
|
100
91
|
- lib/resourceful/resource.rb
|
101
92
|
- lib/resourceful/version.rb
|
102
93
|
- lib/resourceful.rb
|
103
|
-
- test/test_helper.rb
|
104
94
|
has_rdoc: true
|
105
95
|
homepage: ""
|
96
|
+
licenses:
|
106
97
|
post_install_message:
|
107
98
|
rdoc_options:
|
108
99
|
- --main
|
@@ -124,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
115
|
requirements: []
|
125
116
|
|
126
117
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.3.5
|
128
119
|
signing_key:
|
129
120
|
specification_version: 2
|
130
121
|
summary: A ruby gem to abstract web resource handling.
|
data/features/models.feature
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Feature: Models
|
2
|
-
In order to consume rest based resources
|
3
|
-
As an object
|
4
|
-
I want to define and initialize a model class from resource data
|
5
|
-
|
6
|
-
Scenario: Get JSON user
|
7
|
-
Given I am user with the screen_name "kelredd"
|
8
|
-
When I load my "Json" user model
|
9
|
-
Then the result should be a valid User model
|
10
|
-
|
11
|
-
Scenario: Get XML user
|
12
|
-
Given I am user with the screen_name "kelredd"
|
13
|
-
When I load my "Xml" user model
|
14
|
-
Then the result should be a valid User model
|
15
|
-
|
16
|
-
Scenario: Get JSON status collection
|
17
|
-
When I load the "Json" status "public_timeline"
|
18
|
-
Then the result should be a collection of valid Status models
|
19
|
-
|
20
|
-
Scenario: Get XML status collection
|
21
|
-
When I load the "Xml" status "public_timeline"
|
22
|
-
Then the result should be a collection of valid Status models
|
@@ -1,61 +0,0 @@
|
|
1
|
-
Feature: Get Resource
|
2
|
-
In order to consume rest based resources
|
3
|
-
As an object
|
4
|
-
I want to get data from a web resource as a formatted object
|
5
|
-
|
6
|
-
Scenario: JSON Format definition
|
7
|
-
Given I want to use the json resource format
|
8
|
-
Then the format should be .json
|
9
|
-
|
10
|
-
Scenario: XML Format definition
|
11
|
-
Given I want to use the xml resource format
|
12
|
-
Then the format should be .xml
|
13
|
-
|
14
|
-
Scenario: Host not configured
|
15
|
-
Given I have no host server configured
|
16
|
-
Then resourceful should complain about a configuration error
|
17
|
-
|
18
|
-
Scenario: Host configured
|
19
|
-
Given I have a configured resource host
|
20
|
-
Then the host should be set
|
21
|
-
|
22
|
-
Scenario: Resource logger
|
23
|
-
Given I have a configured resource host set to log
|
24
|
-
Then verify the log settings
|
25
|
-
|
26
|
-
Scenario: Resource logging
|
27
|
-
Given I have a configured resource host set to log
|
28
|
-
When I get a json formatted resource
|
29
|
-
Then the set log file should exist
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Scenario: Get JSON resource
|
34
|
-
Given I have a configured resource host
|
35
|
-
When I get a json formatted resource
|
36
|
-
Then the result should be a hash object
|
37
|
-
|
38
|
-
Scenario: Get XML resource
|
39
|
-
Given I have a configured resource host
|
40
|
-
When I get an xml formatted resource
|
41
|
-
Then the result should be an xml object
|
42
|
-
|
43
|
-
Scenario: Get an implicit format JSON resource
|
44
|
-
Given I have a configured resource host
|
45
|
-
When I get a json formatted implicitly resource
|
46
|
-
Then the result should be a hash object
|
47
|
-
|
48
|
-
Scenario: Get an implicit format XML resource
|
49
|
-
Given I have a configured resource host
|
50
|
-
When I get an xml formatted implicitly resource
|
51
|
-
Then the result should be an xml object
|
52
|
-
|
53
|
-
Scenario: Get resource with format not supported
|
54
|
-
Given I have a configured resource host
|
55
|
-
When I get an poop formatted resource
|
56
|
-
Then resourceful should complain about a format error
|
57
|
-
|
58
|
-
Scenario: Get non existent resource
|
59
|
-
Given I have a configured resource host
|
60
|
-
When I get a resource that does not exist
|
61
|
-
Then resourceful should complain about the resource not being found
|
@@ -1,63 +0,0 @@
|
|
1
|
-
Given /^I am user with the screen_name "([^\"]*)"$/ do |screen_name|
|
2
|
-
@screen_name = screen_name
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I load my "([^\"]*)" user model$/ do |klass|
|
6
|
-
@result = "User#{klass}".constantize.find(@screen_name)
|
7
|
-
end
|
8
|
-
|
9
|
-
When /^I load the "([^\"]*)" status "([^\"]*)"$/ do |klass, collection|
|
10
|
-
@result = "Status#{klass}".constantize.find(collection)
|
11
|
-
end
|
12
|
-
|
13
|
-
Then /^the result should be a valid User model$/ do
|
14
|
-
[:id, :name, :screen_name, :location, :description, :profile_image_url, :url, :protected, :followers_count, :friends_count, :created_on, :last_status_at, :last_status].each do |attribute|
|
15
|
-
assert @result.respond_to?(attribute)
|
16
|
-
end
|
17
|
-
{
|
18
|
-
:id => 38225297,
|
19
|
-
:name => "Kelly Redding",
|
20
|
-
:screen_name => "kelredd",
|
21
|
-
:protected => false,
|
22
|
-
:created_on => Date.strptime("2009-05-06")
|
23
|
-
}.each do |k,v|
|
24
|
-
assert_equal v, @result.send(k.to_s)
|
25
|
-
end
|
26
|
-
assert_kind_of DateTime, @result.last_status_at
|
27
|
-
assert !@result.last_status.nil?
|
28
|
-
assert @result.last_status != ''
|
29
|
-
|
30
|
-
assert_kind_of Resourceful::Model::Base, @result.last_status
|
31
|
-
assert_valid_status(@result.last_status)
|
32
|
-
end
|
33
|
-
|
34
|
-
Then /^the result should be a collection of valid Status models$/ do
|
35
|
-
assert_kind_of Array, @result
|
36
|
-
assert_equal 20, @result.length
|
37
|
-
assert_valid_status(@result.first)
|
38
|
-
|
39
|
-
[:user_id, :user_screen_name, :user].each do |attribute|
|
40
|
-
assert @result.first.respond_to?(attribute)
|
41
|
-
assert_nothing_raised do
|
42
|
-
@result.first.send(attribute.to_s)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
[:user_id, :user_screen_name, :user].each do |attribute|
|
46
|
-
assert !@result.first.send(attribute.to_s).nil?
|
47
|
-
end
|
48
|
-
assert_kind_of Resourceful::Model::Base, @result.first.user
|
49
|
-
end
|
50
|
-
|
51
|
-
def assert_valid_status(status)
|
52
|
-
[:id, :text, :source, :truncated, :favorited, :reply_status, :reply_user].each do |attribute|
|
53
|
-
assert status.respond_to?(attribute)
|
54
|
-
assert_nothing_raised do
|
55
|
-
status.send(attribute.to_s)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
[:id, :text, :truncated, :favorited].each do |attribute|
|
60
|
-
assert !status.send(attribute.to_s).nil?
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
Given /^I want to use the (.+) resource format$/ do |format|
|
2
|
-
@format = Resourceful::Resource::Format.get(format)
|
3
|
-
end
|
4
|
-
|
5
|
-
Given /^I have no host server configured$/ do
|
6
|
-
@agent = Resourceful::Agent::RestClient.new
|
7
|
-
end
|
8
|
-
|
9
|
-
Given /^I have a configured resource host$/ do
|
10
|
-
@agent = Resourceful::Agent::RestClient.new(:host => RESOURCE_CONFIG[:host])
|
11
|
-
end
|
12
|
-
|
13
|
-
Given /^I have a configured resource host set to log$/ do
|
14
|
-
log_file = File.expand_path(RESOURCE_CONFIG[:log])
|
15
|
-
FileUtils.rm(log_file) if File.exists?(log_file)
|
16
|
-
@agent = Resourceful::Agent::RestClient.new(:host => RESOURCE_CONFIG[:host]) {
|
17
|
-
RESOURCE_CONFIG[:log]
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
Then /^the format should be \.(.+)$/ do |format|
|
22
|
-
assert_equal @format.to_s, format
|
23
|
-
end
|
24
|
-
|
25
|
-
Then /^the host should be set$/ do
|
26
|
-
assert_equal @agent.host, RESOURCE_CONFIG[:host]
|
27
|
-
end
|
28
|
-
|
29
|
-
Then /^resourceful should complain about a configuration error$/ do
|
30
|
-
assert_raise Resourceful::Exceptions::ConfigurationError do
|
31
|
-
@agent.get RESOURCE_CONFIG[:resource], :format => 'json', :params => RESOURCE_CONFIG[:params]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Then /^verify the log settings$/ do
|
36
|
-
assert_equal @agent.logger.outputters.detect{|out| out.respond_to?('filename')}.filename, RESOURCE_CONFIG[:log]
|
37
|
-
end
|
38
|
-
|
39
|
-
Then /^the set log file should exist$/ do
|
40
|
-
log_file = File.expand_path(RESOURCE_CONFIG[:log])
|
41
|
-
assert File.exists?(log_file)
|
42
|
-
FileUtils.rm(log_file) if File.exists?(log_file)
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
When /^I get a[n]* (.+) formatted resource$/ do |format|
|
49
|
-
@result = ResourcefulFeature::Helpers.safe_run_get do
|
50
|
-
@agent.get RESOURCE_CONFIG[:resource], :format => format, :params => RESOURCE_CONFIG[:params]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
When /^I get a[n]* (.+) formatted implicitly resource$/ do |format|
|
55
|
-
@result = ResourcefulFeature::Helpers.safe_run_get do
|
56
|
-
@agent.get RESOURCE_CONFIG[:resource]+".#{format}", :params => RESOURCE_CONFIG[:params]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
When /^I get a resource that does not exist$/ do
|
61
|
-
@result = ResourcefulFeature::Helpers.safe_run_get do
|
62
|
-
@agent.get '/unknown', :format => 'xml', :params => RESOURCE_CONFIG[:params]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
Then /^the result should be a hash object$/ do
|
67
|
-
assert_kind_of Hash, @result.first
|
68
|
-
end
|
69
|
-
|
70
|
-
Then /^the result should be an xml object$/ do
|
71
|
-
assert_kind_of Nokogiri::XML::Document, @result
|
72
|
-
end
|
73
|
-
|
74
|
-
Then /^resourceful should complain about a format error$/ do
|
75
|
-
assert @result
|
76
|
-
assert_kind_of Resourceful::Exceptions::FormatError, @result
|
77
|
-
assert @result.message.length > 0
|
78
|
-
end
|
79
|
-
|
80
|
-
Then /^resourceful should complain about the resource not being found$/ do
|
81
|
-
assert @result
|
82
|
-
assert_kind_of RestClient::ResourceNotFound, @result
|
83
|
-
assert @result.message.length > 0
|
84
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'test/unit/assertions'
|
2
|
-
World(Test::Unit::Assertions)
|
3
|
-
|
4
|
-
RESOURCE_CONFIG = {
|
5
|
-
:host => 'http://twitter.com',
|
6
|
-
:resource => '/statuses/public_timeline',
|
7
|
-
:params => {},
|
8
|
-
:log => "./test.log"
|
9
|
-
}
|
10
|
-
|
11
|
-
require File.dirname(__FILE__) + '/../../../lib/resourceful'
|
12
|
-
|
13
|
-
REST_CLIENT_TWITTER = Resourceful::Agent::RestClient.new(:host => RESOURCE_CONFIG[:host])
|
14
|
-
|
@@ -1,97 +0,0 @@
|
|
1
|
-
class UserXml < Resourceful::Model::Xml
|
2
|
-
|
3
|
-
agent REST_CLIENT_TWITTER
|
4
|
-
|
5
|
-
def self.find(screen_name, force=false)
|
6
|
-
get("/users/#{screen_name}", {}, "//user")
|
7
|
-
end
|
8
|
-
|
9
|
-
attribute :id, :integer
|
10
|
-
attribute :name, :string
|
11
|
-
attribute :screen_name, :string
|
12
|
-
attribute :location, :string
|
13
|
-
attribute :description, :string
|
14
|
-
attribute :profile_image_url, :string
|
15
|
-
attribute :url, :string
|
16
|
-
attribute :protected, :boolean
|
17
|
-
attribute :followers_count, :integer
|
18
|
-
attribute :friends_count, :integer
|
19
|
-
attribute :created_on, :date, :path => 'created_at'
|
20
|
-
attribute :last_status_at, :datetime, :path => "status/created_at"
|
21
|
-
attribute :last_status, :string, :path => "status/text"
|
22
|
-
|
23
|
-
has_one :last_status, :path => "status", :klass => "StatusXml"
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
class UserJson < Resourceful::Model::Json
|
28
|
-
|
29
|
-
agent REST_CLIENT_TWITTER
|
30
|
-
|
31
|
-
def self.find(screen_name, force=false)
|
32
|
-
get("/users/#{screen_name}", {})
|
33
|
-
end
|
34
|
-
|
35
|
-
attribute :id, :integer
|
36
|
-
attribute :name, :string
|
37
|
-
attribute :screen_name, :string
|
38
|
-
attribute :location, :string
|
39
|
-
attribute :description, :string
|
40
|
-
attribute :profile_image_url, :string
|
41
|
-
attribute :url, :string
|
42
|
-
attribute :protected, :boolean
|
43
|
-
attribute :followers_count, :integer
|
44
|
-
attribute :friends_count, :integer
|
45
|
-
attribute :created_on, :date, :path => 'created_at'
|
46
|
-
attribute :last_status_at, :datetime, :path => "status/created_at"
|
47
|
-
attribute :last_status, :string, :path => "status/text"
|
48
|
-
|
49
|
-
has_one :last_status, :path => "status", :klass => "StatusJson"
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
class StatusXml < Resourceful::Model::Xml
|
54
|
-
|
55
|
-
agent REST_CLIENT_TWITTER
|
56
|
-
|
57
|
-
def self.find(collection, force=false)
|
58
|
-
get_collection("/statuses/#{collection}", {}, "//statuses/status")
|
59
|
-
end
|
60
|
-
|
61
|
-
attribute :id, :integer
|
62
|
-
attribute :text, :string
|
63
|
-
attribute :source, :string
|
64
|
-
attribute :created_on, :date, :path => 'created_at'
|
65
|
-
attribute :truncated, :boolean
|
66
|
-
attribute :favorited, :boolean
|
67
|
-
attribute :reply_status, :integer, :path => 'in_reply_to_status_id'
|
68
|
-
attribute :reply_user, :integer, :path => 'in_reply_to_user_id'
|
69
|
-
attribute :user_id, :integer, :path => "user/id"
|
70
|
-
attribute :user_screen_name, :integer, :path => "user/screen_name"
|
71
|
-
|
72
|
-
has_one :user, :path => "user", :klass => "UserXml"
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
class StatusJson < Resourceful::Model::Json
|
77
|
-
|
78
|
-
agent REST_CLIENT_TWITTER
|
79
|
-
|
80
|
-
def self.find(collection, force=false)
|
81
|
-
get_collection("/statuses/#{collection}", {})
|
82
|
-
end
|
83
|
-
|
84
|
-
attribute :id, :integer
|
85
|
-
attribute :text, :string
|
86
|
-
attribute :source, :string
|
87
|
-
attribute :created_on, :date, :path => 'created_at'
|
88
|
-
attribute :truncated, :boolean
|
89
|
-
attribute :favorited, :boolean
|
90
|
-
attribute :reply_status, :integer, :path => 'in_reply_to_status_id'
|
91
|
-
attribute :reply_user, :integer, :path => 'in_reply_to_user_id'
|
92
|
-
attribute :user_id, :integer, :path => "user/id"
|
93
|
-
attribute :user_screen_name, :string, :path => "user/screen_name"
|
94
|
-
|
95
|
-
belongs_to :user, :klass => "UserJson"
|
96
|
-
|
97
|
-
end
|