rnow 0.0.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.
- checksums.yaml +7 -0
- data/.byebug_history +167 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/lib/rnow.rb +31 -0
- data/lib/rnow/connection.rb +106 -0
- data/lib/rnow/resource.rb +244 -0
- data/lib/rnow/resources/.DS_Store +0 -0
- data/lib/rnow/resources/account.rb +24 -0
- data/lib/rnow/resources/category.rb +23 -0
- data/lib/rnow/resources/contact.rb +21 -0
- data/lib/rnow/resources/dispositions.rb +23 -0
- data/lib/rnow/resources/incident.rb +40 -0
- data/lib/rnow/resources/organization.rb +24 -0
- data/lib/rnow/resources/product.rb +23 -0
- data/lib/rnow/version.rb +3 -0
- data/rnow.gemspec +28 -0
- data/spec/connection_spec.rb +45 -0
- data/spec/resource_spec.rb +107 -0
- data/spec/spec_helper.rb +103 -0
- metadata +156 -0
@@ -0,0 +1,244 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Resource
|
3
|
+
attr_accessor :href, :connection
|
4
|
+
|
5
|
+
def self.rnow_object(obj=nil)
|
6
|
+
if obj.nil?
|
7
|
+
@rnow_object
|
8
|
+
else
|
9
|
+
self.resource_map[obj] = self
|
10
|
+
@rnow_object = obj
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Define a writeable remote attribute, i.e. one that
|
16
|
+
# should show up in post / put operations.
|
17
|
+
#
|
18
|
+
def self.remote_attr_accessor(*args)
|
19
|
+
args.each do |a|
|
20
|
+
attr_accessor a
|
21
|
+
remote_attrs << a
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Define a remote attribute that can only be sent during a
|
27
|
+
# POST operation.
|
28
|
+
#
|
29
|
+
def self.remote_post_accessor(*args)
|
30
|
+
args.each do |a|
|
31
|
+
attr_accessor a
|
32
|
+
remote_post_attrs << a
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Define a remote attribute that is write-only
|
38
|
+
#
|
39
|
+
def self.remote_attr_writer(*args)
|
40
|
+
args.each do |a|
|
41
|
+
attr_accessor a
|
42
|
+
remote_write_only_attrs << a
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Define a read-only attribute
|
48
|
+
#
|
49
|
+
def self.remote_attr_reader(*args)
|
50
|
+
args.each do |a|
|
51
|
+
attr_reader a
|
52
|
+
remote_read_only_attrs << a
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.remote_attrs
|
57
|
+
@remote_attrs ||= []
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.remote_write_only_attrs
|
61
|
+
@remote_write_only_attrs ||= []
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.remote_read_only_attrs
|
65
|
+
@remote_read_only_attrs ||= []
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.remote_post_attrs
|
69
|
+
@remote_post_attrs ||= []
|
70
|
+
end
|
71
|
+
|
72
|
+
def self._return_fields
|
73
|
+
(self.remote_attrs + self.remote_read_only_attrs).join(",")
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.default_params
|
77
|
+
{:_return_fields => self._return_fields}
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Return an array of all records for this resource.
|
82
|
+
# There is a limit to about 1000 records that are returned here, so
|
83
|
+
# if your resource has more you will need to use paging or search to
|
84
|
+
# retreive what you need.
|
85
|
+
# See self.paginate() for paganition, see self.find() for search support.
|
86
|
+
#
|
87
|
+
def self.all(connection, params = {})
|
88
|
+
JSON.parse(connection.get(resource_uri, params).body)["items"].map do |item|
|
89
|
+
debugger
|
90
|
+
href = item.delete("links").first["href"]
|
91
|
+
new(item.merge({href: href, connection: connection}))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Return an array of paged records for this resource.
|
97
|
+
# The page number from 0-N can be specified
|
98
|
+
# The count is the number of entries returned per page
|
99
|
+
#
|
100
|
+
def self.paginate(connection, params = {page: 0, count: 10})
|
101
|
+
page = params.delete(:page)
|
102
|
+
count = params.delete(:count)
|
103
|
+
uri = Rnow.base_path + 'queryResults';
|
104
|
+
params = {query: URI.escape("select * from #{self.rnow_object} limit #{count} offset #{page}")}
|
105
|
+
response = JSON.parse(connection.get(uri, params).body)
|
106
|
+
keys = response["items"].first["columnNames"]
|
107
|
+
rows = response["items"].first["rows"]
|
108
|
+
resources=[]
|
109
|
+
rows.each do |row|
|
110
|
+
hash = Hash[keys.zip row]
|
111
|
+
resources << new(hash.merge({href: resource_uri + '/' + hash["id"], connection: connection}))
|
112
|
+
end
|
113
|
+
resources
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Find resources with query by key value pair
|
118
|
+
# Typical query patter is:
|
119
|
+
# uri = services/rest/connect/latest/contacts?q=lookupName='Soheil Eizadi'
|
120
|
+
#
|
121
|
+
# Example: Rnow::Contact.find(connection, "lookupName", "Soheil Eizadi")
|
122
|
+
#
|
123
|
+
def self.find(connection, params = {key: nil, value: nil})
|
124
|
+
key = params.delete(:key)
|
125
|
+
value = params.delete(:value)
|
126
|
+
search = (value.is_a? Integer) ? value : "'#{value}'"
|
127
|
+
JSON.parse(connection.get(resource_uri, {q: "#{key}=#{search}"}).body)["items"].map do |item|
|
128
|
+
href = item.delete("links").first["href"]
|
129
|
+
new(item.merge({href: href, connection: connection}))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Find resoures with ROQL using where clause
|
135
|
+
#
|
136
|
+
def self.find_where(connection, params = {key: nil, value: nil, count: 10})
|
137
|
+
key = params.delete(:key)
|
138
|
+
value = params.delete(:value)
|
139
|
+
page = params.delete(:page)
|
140
|
+
count = params.delete(:count)
|
141
|
+
uri = Rnow.base_path + 'queryResults';
|
142
|
+
search = (value.is_a? Integer) ? value : "'#{value}'"
|
143
|
+
params = {query: URI.escape("select * from #{self.rnow_object} where #{key}=#{search}")}
|
144
|
+
response = JSON.parse(connection.get(uri, params).body)
|
145
|
+
keys = response["items"].first["columnNames"]
|
146
|
+
rows = response["items"].first["rows"]
|
147
|
+
resources=[]
|
148
|
+
rows.each do |row|
|
149
|
+
hash = Hash[keys.zip row]
|
150
|
+
resources << new(hash.merge({href: resource_uri + '/' + hash["id"], connection: connection}))
|
151
|
+
end
|
152
|
+
resources
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Filter resources with query by key value pair
|
157
|
+
# Typical query patter is:
|
158
|
+
# uri = "services/rest/connect/latest/contacts?q=lookupName like '%Soheil%'"
|
159
|
+
#
|
160
|
+
# Example: Rnow::Contact.filter(connection, "lookupName", "Soheil Eizadi")
|
161
|
+
#
|
162
|
+
def self.filter(connection, params = {key: nil, value: nil})
|
163
|
+
key = params.delete(:key)
|
164
|
+
value = params.delete(:value)
|
165
|
+
JSON.parse(connection.get(resource_uri, {q: "#{key} like '%#{value}%'"}).body)["items"].map do |item|
|
166
|
+
href = item.fetch("links").first["href"]
|
167
|
+
new(item.merge({href: href, connection: connection}))
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.resource_uri
|
172
|
+
Rnow.base_path + self.rnow_object
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# A hash that maps Rnow WAPI object identifiers to subclasses of Resource.
|
177
|
+
# Used by the Search resource for mapping response objects.
|
178
|
+
#
|
179
|
+
def self.resource_map
|
180
|
+
@@resource_map ||= {}
|
181
|
+
end
|
182
|
+
|
183
|
+
def initialize(attrs={})
|
184
|
+
load_attributes(attrs)
|
185
|
+
end
|
186
|
+
|
187
|
+
def post
|
188
|
+
resource = JSON.parse(connection.post(resource_uri, remote_attribute_hash(write = true, post = true)).body)
|
189
|
+
self.href = resource.fetch("links").first["href"]
|
190
|
+
true
|
191
|
+
end
|
192
|
+
alias_method :create, :post
|
193
|
+
|
194
|
+
def delete
|
195
|
+
connection.delete(resource_uri).status == 200
|
196
|
+
end
|
197
|
+
|
198
|
+
def get(params=self.class.default_params)
|
199
|
+
response = connection.get(resource_uri, params).body
|
200
|
+
load_attributes(JSON.parse(response))
|
201
|
+
self
|
202
|
+
end
|
203
|
+
|
204
|
+
def put
|
205
|
+
resource = JSON.parse(connection.put(resource_uri, remote_attribute_hash(write = true)).body)
|
206
|
+
self.href = resource.fetch("links").first["href"]
|
207
|
+
true
|
208
|
+
end
|
209
|
+
|
210
|
+
def resource_uri
|
211
|
+
self.href.nil? ? self.class.resource_uri : (Rnow.base_path + self.href)
|
212
|
+
end
|
213
|
+
|
214
|
+
def remote_attribute_hash(write=false, post=false)
|
215
|
+
{}.tap do |hsh|
|
216
|
+
self.class.remote_attrs.each do |k|
|
217
|
+
hsh[k] = self.send(k) unless self.send(k).nil?
|
218
|
+
end
|
219
|
+
self.class.remote_write_only_attrs.each do |k|
|
220
|
+
hsh[k] = self.send(k) unless self.send(k).nil?
|
221
|
+
end if write
|
222
|
+
self.class.remote_post_attrs.each do |k|
|
223
|
+
hsh[k] = self.send(k) unless self.send(k).nil?
|
224
|
+
end if post
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def load_attributes(attrs)
|
231
|
+
attrs.each do |k,v|
|
232
|
+
# Some things have specialized writers
|
233
|
+
if respond_to?("#{k}=")
|
234
|
+
send("#{k}=", v)
|
235
|
+
|
236
|
+
# Some things don't have writers (i.e. remote_attr_reader fields)
|
237
|
+
else
|
238
|
+
instance_variable_set("@#{k}", v)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Account < Resource
|
3
|
+
remote_attr_accessor :login,
|
4
|
+
:lookupName
|
5
|
+
|
6
|
+
remote_attr_reader :id,
|
7
|
+
:createdTime,
|
8
|
+
:updatedTime
|
9
|
+
|
10
|
+
rnow_object "accounts"
|
11
|
+
|
12
|
+
def delete
|
13
|
+
raise "Not supported"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
raise "Not supported"
|
18
|
+
end
|
19
|
+
|
20
|
+
def modify
|
21
|
+
raise "Not supported"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Category < Resource
|
3
|
+
remote_attr_accessor :lookupName
|
4
|
+
|
5
|
+
remote_attr_reader :id,
|
6
|
+
:createdTime,
|
7
|
+
:updatedTime
|
8
|
+
|
9
|
+
rnow_object "serviceCategories"
|
10
|
+
|
11
|
+
def delete
|
12
|
+
raise "Not supported"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
raise "Not supported"
|
17
|
+
end
|
18
|
+
|
19
|
+
def modify
|
20
|
+
raise "Not supported"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Contact < Resource
|
3
|
+
remote_attr_accessor :login,
|
4
|
+
:lookupName,
|
5
|
+
:organization
|
6
|
+
|
7
|
+
remote_attr_reader :id,
|
8
|
+
:createdTime,
|
9
|
+
:updatedTime
|
10
|
+
|
11
|
+
rnow_object "contacts"
|
12
|
+
|
13
|
+
def delete
|
14
|
+
raise "Not supported"
|
15
|
+
end
|
16
|
+
|
17
|
+
def modify
|
18
|
+
raise "Not supported"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Disposition < Resource
|
3
|
+
remote_attr_accessor :lookupName
|
4
|
+
|
5
|
+
remote_attr_reader :id,
|
6
|
+
:createdTime,
|
7
|
+
:updatedTime
|
8
|
+
|
9
|
+
rnow_object "serviceDispositions"
|
10
|
+
|
11
|
+
def delete
|
12
|
+
raise "Not supported"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
raise "Not supported"
|
17
|
+
end
|
18
|
+
|
19
|
+
def modify
|
20
|
+
raise "Not supported"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Incident < Resource
|
3
|
+
remote_attr_accessor :lookupName,
|
4
|
+
:subject,
|
5
|
+
:asset,
|
6
|
+
:category,
|
7
|
+
:channel,
|
8
|
+
:disposition,
|
9
|
+
:initialResponseDueTime,
|
10
|
+
:initialSolutionTime,
|
11
|
+
:lastResponseTime,
|
12
|
+
:mailbox,
|
13
|
+
:mailing,
|
14
|
+
:organization,
|
15
|
+
:product,
|
16
|
+
:referenceNumber,
|
17
|
+
:resolutionInterval,
|
18
|
+
:responseEmailAddressType,
|
19
|
+
:responseInterval,
|
20
|
+
:severity,
|
21
|
+
:source
|
22
|
+
|
23
|
+
remote_attr_reader :id,
|
24
|
+
:createdTime,
|
25
|
+
:updatedTime
|
26
|
+
|
27
|
+
remote_post_accessor :assignedTo,
|
28
|
+
:primaryContact
|
29
|
+
|
30
|
+
rnow_object "incidents"
|
31
|
+
|
32
|
+
def delete
|
33
|
+
raise "Not supported"
|
34
|
+
end
|
35
|
+
|
36
|
+
def modify
|
37
|
+
raise "Not supported"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Organization < Resource
|
3
|
+
remote_attr_accessor :lookupName,
|
4
|
+
:login
|
5
|
+
|
6
|
+
remote_attr_reader :id,
|
7
|
+
:createdTime,
|
8
|
+
:updatedTime
|
9
|
+
|
10
|
+
rnow_object "organizations"
|
11
|
+
|
12
|
+
def delete
|
13
|
+
raise "Not supported"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
raise "Not supported"
|
18
|
+
end
|
19
|
+
|
20
|
+
def modify
|
21
|
+
raise "Not supported"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Product < Resource
|
3
|
+
remote_attr_accessor :lookupName
|
4
|
+
|
5
|
+
remote_attr_reader :id,
|
6
|
+
:createdTime,
|
7
|
+
:updatedTime
|
8
|
+
|
9
|
+
rnow_object "serviceProducts"
|
10
|
+
|
11
|
+
def delete
|
12
|
+
raise "Not supported"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
raise "Not supported"
|
17
|
+
end
|
18
|
+
|
19
|
+
def modify
|
20
|
+
raise "Not supported"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/rnow/version.rb
ADDED
data/rnow.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rnow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rnow"
|
8
|
+
spec.version = Rnow::VERSION
|
9
|
+
spec.authors = ["Soheil Eizadi"]
|
10
|
+
spec.email = ["seizadi@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for Oracle RightNow REST API}
|
12
|
+
spec.description = %q{Ruby Gem for Oracle RightNow REST interface, was available with version 15.05 (May 2015). Use this gem to list, create, and delete RightNow organizations, contacts and incdents.}
|
13
|
+
spec.homepage = "https://github.com/seizadi/rnow"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "faraday", "~> 0.9.2"
|
26
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.10.0"
|
27
|
+
spec.add_runtime_dependency "jsonapi-serializers", "~> 0.6.4"
|
28
|
+
end
|