astroboa-rb 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/CHANGELOG.rdoc +0 -0
- data/COPYING +675 -0
- data/COPYING.LESSER +166 -0
- data/Gemfile +4 -0
- data/LICENSE +18 -0
- data/README.md +122 -0
- data/Rakefile +1 -0
- data/astroboa-rb.gemspec +27 -0
- data/lib/astroboa-rb.rb +5 -0
- data/lib/astroboa-rb/client.rb +362 -0
- data/lib/astroboa-rb/clienterror.rb +41 -0
- data/lib/astroboa-rb/version.rb +3 -0
- data/test/features/astroboaClient.feature +46 -0
- data/test/features/step_definitions/astroboaClientSteps.rb +148 -0
- metadata +129 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# This is the base AstroboaClient exception class.
|
2
|
+
# For your convenience you do not need to write rescue code for each astroboa client api call.
|
3
|
+
# If an error occurs the exception is not directly raised but rather it is passed to
|
4
|
+
# either an exception hadling error block that you may provide in each api call
|
5
|
+
# or otherwise to the generic error callback that you have specified by means of the "on_error" method
|
6
|
+
# if you provide no error handling block and no generic error callback is set then a non successful api call returns nil as a response
|
7
|
+
# All succeful api calls return non nil responses so a quick and easy way to check the success of the call without writing error
|
8
|
+
# handling blocks is to check for a non nil response.
|
9
|
+
# You can get the status code of the api call (i.e the corresponding http code) by e.api_code.
|
10
|
+
# if any response related to the error has been returned, you may see the response by e.api_response
|
11
|
+
# A message related to the error is available at e.message
|
12
|
+
# Use e.inspet or e.to_s to get the error message as well as the api response
|
13
|
+
|
14
|
+
module Astroboa
|
15
|
+
|
16
|
+
class ClientError < RuntimeError
|
17
|
+
|
18
|
+
attr_accessor :api_response, :api_code
|
19
|
+
attr_writer :message
|
20
|
+
|
21
|
+
def initialize message = nil, api_code = nil, api_response = nil
|
22
|
+
@message = message
|
23
|
+
@api_code = api_code
|
24
|
+
@api_response = api_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#{message}: #{api_response}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
inspect
|
33
|
+
end
|
34
|
+
|
35
|
+
def message
|
36
|
+
@message || self.class.name
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Astroboa Ruby Client
|
2
|
+
Develop an astroboa ruby client that enables ruby developers
|
3
|
+
to easily read, write and search astroboa resources from ruby programs.
|
4
|
+
The client eliminates the need to execute raw http calls
|
5
|
+
to the astroboa REST API and hides the REST API details.
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given the following text resources persisted to astroboa
|
9
|
+
| contentObjectTypeName | profile.title | body |
|
10
|
+
| genericContentResourceObject | Test Resource 1 | Hello World 1 |
|
11
|
+
| genericContentResourceObject | Test Resource 2 | Hello World 2 |
|
12
|
+
| genericContentResourceObject | Test Resource to be updated | This text will be updated soon |
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: Create a new text resource (contentObjectTypeName="genericContentResourceObject") with title "Test Resource" and body "Hello World"
|
16
|
+
Given a text resource (stored in hash "my_new_text_resource") with title "Test Resource" and body "Hello World" has already been persisted to astroboa
|
17
|
+
Then an id has been assigned to it
|
18
|
+
And the new resource id is returned by the call
|
19
|
+
|
20
|
+
Scenario: Read as hash an existing text resource using its id as identifier
|
21
|
+
Given a text resource (stored in hash "my_new_text_resource") with title "Test Resource 2" and body "Hello World again" has already been persisted to astroboa
|
22
|
+
And the id of the persisted resource is stored in variable "id_of_resource_to_read"
|
23
|
+
When method getObject(id_of_resource_to_read) is called
|
24
|
+
Then a hash object with the resource is returned
|
25
|
+
|
26
|
+
Scenario: Read as object an existing text resource using its id as identifier
|
27
|
+
Given a text resource (stored in hash "my_new_text_resource") with title "Test Resource 2" and body "Hello World again" has already been persisted to astroboa
|
28
|
+
And the id of the persisted resource is stored in variable "id_of_resource_to_read"
|
29
|
+
When method getObject(id_of_resource_to_read, nil, :object) is called
|
30
|
+
Then an Openstruct object with the resource is returned
|
31
|
+
|
32
|
+
Scenario: Update the body text of an existing text resource
|
33
|
+
Given a text resource (stored in hash "my_new_text_resource") with title "Test Resource to be updated" and body "This text will be updated soon" has already been persisted to astroboa
|
34
|
+
And the id of the persisted resource is stored in variable "id_of_resource_to_update"
|
35
|
+
When method updateObject({"contentObjectTypeName" => "genericContentResourceObject", "cmsIdentifier" => id_of_resource_to_update, "body" => "Updated Body Text"}) is called
|
36
|
+
Then the body text of the persisted text resource is "Updated Body Text"
|
37
|
+
|
38
|
+
Scenario: Get a collection of all text resources that their body contains the word hello
|
39
|
+
Given a text resource (stored in hash "my_new_text_resource") with title "Hello is contained in body text" and body "The word hello is contained in this text" has already been persisted to astroboa
|
40
|
+
And the id of the persisted resource is stored in variable "id_of_resource"
|
41
|
+
When method getObjectCollection('contentTypeName="genericContentResourceObject" AND body CONTAINS "Hello"') is called
|
42
|
+
Then the persisted resource is contained in the resource collection we get back
|
43
|
+
|
44
|
+
Scenario: Get all object types modeled in the repository
|
45
|
+
When method getModel is called and the argument "objectTypeOrProperty" is absent or equal to the empty string
|
46
|
+
Then a hash with all object types modeled in the repository is returned and the hash contains the core object type "fileResourceObject"
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
|
3
|
+
require 'rspec/expectations'
|
4
|
+
require 'cucumber/formatter/unicode'
|
5
|
+
$:.unshift(File.dirname(__FILE__) + '/../../../lib')
|
6
|
+
require 'astroboa-rb'
|
7
|
+
|
8
|
+
Before do
|
9
|
+
@astroboaClient = Astroboa::Client.new('localhost:8080', 'altcine', 'SYSTEM', 'altcine2010')
|
10
|
+
@astroboaClient.on_error do |exception|
|
11
|
+
puts exception.message
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
After do
|
16
|
+
end
|
17
|
+
|
18
|
+
Given /^the following text resources persisted to astroboa$/ do |table|
|
19
|
+
# table is a Cucumber::Ast::Table
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# CREATE A NEW TEXT RESOURCE (ASTROBOA OBJECT OF TYPE genericContentResourceObject)
|
24
|
+
Given /^a text resource \(stored in hash "my_new_text_resource"\) with title "([^"]*)" and body "([^"]*)" has already been persisted to astroboa$/ do |title, body|
|
25
|
+
step "a hash object named \"my_new_text_resource\" is created that holds the text resource property values, i\.e\. title=\"#{title}\" and body=\"#{body}\""
|
26
|
+
step "method createObject(my_new_text_resource) is called"
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^a hash object named "my_new_text_resource" is created that holds the text resource property values, i\.e\. title="([^"]*)" and body="([^"]*)"$/ do |title, body|
|
30
|
+
@my_new_text_resource = {"contentObjectTypeName" => "genericContentResourceObject", "profile" => {"title" => title}, "body" => body}
|
31
|
+
puts "this is the resource hash before it is persisted: #{@my_new_text_resource}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# CREATE ASTROBOA OBJECT FROM RUBY HASH
|
38
|
+
When /^method createObject\(my_new_text_resource\) is called$/ do
|
39
|
+
@my_new_text_resource_id = @astroboaClient.createObject @my_new_text_resource
|
40
|
+
end
|
41
|
+
|
42
|
+
Then /^an id has been assigned to it$/ do
|
43
|
+
@my_new_text_resource['cmsIdentifier'].should_not eq(nil)
|
44
|
+
puts "this is the resource hash after it is persisted: #{@my_new_text_resource}"
|
45
|
+
end
|
46
|
+
|
47
|
+
Then /^the new resource id is returned by the call$/ do
|
48
|
+
@my_new_text_resource_id.should_not eq(nil)
|
49
|
+
puts "the call has returned: #{@my_new_text_resource_id}"
|
50
|
+
end
|
51
|
+
|
52
|
+
Given /^the id of the persisted resource is stored in variable "([^"]*)"$/ do |id_of_resource|
|
53
|
+
self.instance_variable_set("@#{id_of_resource}", @my_new_text_resource_id)
|
54
|
+
id = self.instance_variable_get("@#{id_of_resource}")
|
55
|
+
puts "The id is: #{id}"
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# READ ASTROBOA OBJECT AS RUBY HASH
|
62
|
+
When /^method getObject\(id_of_resource_to_read\) is called$/ do
|
63
|
+
@retrieved_text_resource = @astroboaClient.getObject @id_of_resource_to_read
|
64
|
+
end
|
65
|
+
|
66
|
+
Then /^a hash object with the resource is returned$/ do
|
67
|
+
@retrieved_text_resource.should_not eq(nil)
|
68
|
+
@retrieved_text_resource['cmsIdentifier'].should eq(@id_of_resource_to_read)
|
69
|
+
puts "The retrieved resource is: #{@retrieved_text_resource}"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
# READ ASTROBOA OBJECT AS RUBY OBJECT
|
77
|
+
When /^method getObject\(id_of_resource_to_read, nil, :object\) is called$/ do
|
78
|
+
@retrieved_text_resource = @astroboaClient.getObject(@id_of_resource_to_read, nil, :object)
|
79
|
+
end
|
80
|
+
|
81
|
+
Then /^an Openstruct object with the resource is returned$/ do
|
82
|
+
@retrieved_text_resource.should_not eq(nil)
|
83
|
+
@retrieved_text_resource.cmsIdentifier.should eq(@id_of_resource_to_read)
|
84
|
+
@retrieved_text_resource.profile.title.should eq('Test Resource 2')
|
85
|
+
puts "The retrieved resource is: #{@retrieved_text_resource}"
|
86
|
+
end
|
87
|
+
|
88
|
+
#Given /^the id of the persisted resource is stored in variable "id_of_resource_to_update"$/ do
|
89
|
+
# @id_of_resource_to_update = @my_new_text_resource_id
|
90
|
+
# puts "The id is: #{@id_of_resource_to_update}"
|
91
|
+
#end
|
92
|
+
|
93
|
+
# UPDATE EXISTING ASTROBOA OBJECT
|
94
|
+
When /^method updateObject\(([^\)]*)\) is called$/ do |resource_hash_string|
|
95
|
+
resource = {"contentObjectTypeName" => "genericContentResourceObject", "cmsIdentifier" => @id_of_resource_to_update, "body" => "Updated Body Text"}
|
96
|
+
response = @astroboaClient.updateObject resource
|
97
|
+
response.should_not eq(nil)
|
98
|
+
puts "response is: #{response}"
|
99
|
+
end
|
100
|
+
|
101
|
+
Then /^the body text of the persisted text resource is "([^"]*)"$/ do |body_text|
|
102
|
+
text_resource = @astroboaClient.getObject @id_of_resource_to_update
|
103
|
+
text_resource['body'].should eq(body_text)
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
# GET A COLLECTION OF OBJECTS (i.e. search in astroboa with criteria and get back a collection of objects that meet the criteria)
|
109
|
+
When /^method getObjectCollection\('objectType="genericContentResourceObject" AND body CONTAINS "Hello"'\) is called$/ do
|
110
|
+
query = 'objectType="genericContentResourceObject" AND body CONTAINS "Hello"'
|
111
|
+
@resource_collection = @astroboaClient.getObjectCollection(query)
|
112
|
+
@resource_collection.should_not eq(nil)
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
Then /^the persisted resource is contained in the resource collection we get back$/ do
|
117
|
+
text_resources = @resource_collection['resourceCollection']['resource']
|
118
|
+
found_id = nil
|
119
|
+
puts "Looking for resource #{@id_of_resource}"
|
120
|
+
text_resources.each do |text_resource|
|
121
|
+
puts text_resource['cmsIdentifier']
|
122
|
+
if text_resource['cmsIdentifier'] == @id_of_resource
|
123
|
+
found_id = text_resource['cmsIdentifier']
|
124
|
+
break
|
125
|
+
end
|
126
|
+
end
|
127
|
+
puts found_id
|
128
|
+
found_id.should_not eq(nil)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# READ ALL MODELED OBJECT TYPES (i.e. if no object type or property is specified when callint the getModel method then all object types are returned)
|
133
|
+
When /^method getModel is called and the argument "objectTypeOrProperty" is absent or equal to the empty string$/ do
|
134
|
+
@resource_type_collection = @astroboaClient.getModel
|
135
|
+
@resource_type_collection.should_not eq(nil)
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^a hash with all object types modeled in the repository is returned and the hash contains the core object type "([^"]*)"$/ do |expected_object_type|
|
139
|
+
object_types = @resource_type_collection['arrayOfObjectTypes']['objectType']
|
140
|
+
found_type = nil
|
141
|
+
object_types.each do |object_type|
|
142
|
+
if object_type['name'] == expected_object_type
|
143
|
+
found_type = object_type['name']
|
144
|
+
break
|
145
|
+
end
|
146
|
+
end
|
147
|
+
found_type.should_not eq(nil)
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astroboa-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BetaCONCEPT
|
9
|
+
- Gregory Chomatas
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.6'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.6'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: json
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.6'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.6'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: cucumber
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.1'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec-expectations
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.8'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.8'
|
79
|
+
description: Provides easy access to the REST-based 'Astroboa Resource API'. With
|
80
|
+
just a few lines of code you can read, write and search semi-structured content
|
81
|
+
to any astroboa repository hosted in any server in the world.
|
82
|
+
email:
|
83
|
+
- support@betaconcept.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- CHANGELOG.rdoc
|
90
|
+
- COPYING
|
91
|
+
- COPYING.LESSER
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- astroboa-rb.gemspec
|
97
|
+
- lib/astroboa-rb.rb
|
98
|
+
- lib/astroboa-rb/client.rb
|
99
|
+
- lib/astroboa-rb/clienterror.rb
|
100
|
+
- lib/astroboa-rb/version.rb
|
101
|
+
- test/features/astroboaClient.feature
|
102
|
+
- test/features/step_definitions/astroboaClientSteps.rb
|
103
|
+
homepage: http://www.astroboa.org
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project: astroboa-rb
|
123
|
+
rubygems_version: 1.8.23
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Astroboa Client for Ruby.
|
127
|
+
test_files:
|
128
|
+
- test/features/astroboaClient.feature
|
129
|
+
- test/features/step_definitions/astroboaClientSteps.rb
|