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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 04ea26cf6ff542dba07ddc744e63abbcc0137dc3
|
4
|
+
data.tar.gz: a909855b5b6172c2a58d8018fe1ba6254524df9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 234da4a45ec8f44e11ea6d9fc25cf3b7084594d63e94f759b7a877c264183e36840abb2d80650cba6dbdca8fb30d090d8974a0f5616b104d656a23decf23c6d2
|
7
|
+
data.tar.gz: d9524f9455d62772371a1f29aaba9ea156fe00c632f54b44aa82a4ece8ed567cd5745d32f131efca060cd442a94cde20458b6e4aa5cb68ba8b52cd47f8a070ad
|
data/.byebug_history
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
connection.get(resource_uri, params).body
|
2
|
+
connection.class
|
3
|
+
c
|
4
|
+
n
|
5
|
+
connection.get(resource_uri, params).body
|
6
|
+
params
|
7
|
+
c
|
8
|
+
self.href
|
9
|
+
n
|
10
|
+
c
|
11
|
+
i1["links"].first["href"]
|
12
|
+
i1["links"]
|
13
|
+
i2 = new(i1)
|
14
|
+
i1["organization"]
|
15
|
+
i1["id"]
|
16
|
+
i1
|
17
|
+
i1.id
|
18
|
+
ref.body
|
19
|
+
i1.organization
|
20
|
+
i1
|
21
|
+
i1 = JSON.parse(ref.body)
|
22
|
+
ref = connection.post(resource_uri, remote_attribute_hash(write = true, post = true))
|
23
|
+
c
|
24
|
+
remote_attribute_hash(write = true, post = true)
|
25
|
+
quit
|
26
|
+
connection.class
|
27
|
+
c
|
28
|
+
n
|
29
|
+
remote_attribute_hash(write = true, post = true)
|
30
|
+
quit
|
31
|
+
remote_attribute_hash(write = true, post = true)
|
32
|
+
c
|
33
|
+
self.class.remote_attrs
|
34
|
+
remote_attribute_hash(write = true, post = true)
|
35
|
+
resource_uri
|
36
|
+
c
|
37
|
+
count
|
38
|
+
n
|
39
|
+
page
|
40
|
+
n
|
41
|
+
params
|
42
|
+
quit
|
43
|
+
f.login
|
44
|
+
f.lookupName
|
45
|
+
f.id
|
46
|
+
f = new(dummy)
|
47
|
+
dummy = hash.merge({href: resource_uri + '/' + hash["id"], connection: connection})
|
48
|
+
n
|
49
|
+
s
|
50
|
+
n
|
51
|
+
s
|
52
|
+
n
|
53
|
+
hash
|
54
|
+
s
|
55
|
+
n
|
56
|
+
hash
|
57
|
+
quit
|
58
|
+
connection.get(JSON.parse(a.body)["links"].first["href"])
|
59
|
+
JSON.parse(a.body)["links"].first["href"]
|
60
|
+
JSON.parse(a.body)["links"].first[:href]
|
61
|
+
JSON.parse(a.body)["links"]
|
62
|
+
JSON.parse(a.body).class
|
63
|
+
JSON.parse(a.body)["href"]
|
64
|
+
JSON.parse(a.body)[:href]
|
65
|
+
JSON.parse(a.body)
|
66
|
+
JSON.parse(a)
|
67
|
+
a
|
68
|
+
a["id"]
|
69
|
+
a
|
70
|
+
a = connection.get(dummy[:href])
|
71
|
+
connection.get(dummy[:href])
|
72
|
+
dummy
|
73
|
+
quit
|
74
|
+
{href: resource_uri + '/' + h["id"]}
|
75
|
+
h[:href]
|
76
|
+
{href: resource_uri + '/' + h["id"]}
|
77
|
+
h.merge({})
|
78
|
+
n
|
79
|
+
h.merge({})
|
80
|
+
h
|
81
|
+
n
|
82
|
+
s
|
83
|
+
n
|
84
|
+
h.merge({})
|
85
|
+
h
|
86
|
+
quit
|
87
|
+
c
|
88
|
+
Rnow::Contact.rnow_object.class
|
89
|
+
Rnow::Contact.rnow_object
|
90
|
+
Rnow::Contact.hash
|
91
|
+
h.merge({href: resource_uri + '/' + h["id"]})
|
92
|
+
h[:href]
|
93
|
+
h["id"]
|
94
|
+
h.merge({})
|
95
|
+
h
|
96
|
+
c
|
97
|
+
rows.map {|r| Hash[keys.zip r]}
|
98
|
+
rows
|
99
|
+
keys
|
100
|
+
quit
|
101
|
+
b.map {|array| Hash[a.zip array]}
|
102
|
+
Hash[a.zip b.zip]
|
103
|
+
Hash[a.zip b]
|
104
|
+
[a.zip c]
|
105
|
+
a.zip
|
106
|
+
Hash[a.zip c]
|
107
|
+
c = [ 7, 8, 9 ]
|
108
|
+
b = [[10, 11, 12], [20, 21, 22], [30, 31, 32]]
|
109
|
+
a = [ 4, 5, 6 ]
|
110
|
+
keys.zip
|
111
|
+
response["items"].first["rows"].first
|
112
|
+
response["items"].first["rows"]
|
113
|
+
keys
|
114
|
+
n
|
115
|
+
quit
|
116
|
+
n
|
117
|
+
response["items"].first["columnNames"]
|
118
|
+
response["items"].count
|
119
|
+
response["items"]
|
120
|
+
response
|
121
|
+
response["items"]["columnNames"]
|
122
|
+
quit
|
123
|
+
item["columnNames"]
|
124
|
+
item
|
125
|
+
quit
|
126
|
+
n
|
127
|
+
c
|
128
|
+
params
|
129
|
+
n
|
130
|
+
uri
|
131
|
+
n
|
132
|
+
params
|
133
|
+
count
|
134
|
+
page
|
135
|
+
n
|
136
|
+
params
|
137
|
+
quit
|
138
|
+
c
|
139
|
+
n
|
140
|
+
href
|
141
|
+
n
|
142
|
+
quit
|
143
|
+
href=item.delete["links"]
|
144
|
+
item
|
145
|
+
quit
|
146
|
+
n
|
147
|
+
c
|
148
|
+
JSON.parse(connection.get(resource_uri, params).body)["items"].first.merge({:connection => connection})
|
149
|
+
JSON.parse(connection.get(resource_uri, params).body)["items"].first
|
150
|
+
c
|
151
|
+
n
|
152
|
+
item
|
153
|
+
n
|
154
|
+
item={data: item}
|
155
|
+
item
|
156
|
+
n
|
157
|
+
pwd
|
158
|
+
item={data: item}
|
159
|
+
item={item}
|
160
|
+
item
|
161
|
+
quit
|
162
|
+
n
|
163
|
+
params={}
|
164
|
+
params
|
165
|
+
n
|
166
|
+
params={}
|
167
|
+
default_params
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Soheil Eizadi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# RNow
|
2
|
+
|
3
|
+
Interact with the Oracle RightNow REST interface with Ruby. Use this gem to list, create, and delete RightNow organizations, contacts and incdents. The Orcale RightNow REST Interface was available with version 15.05 (May 2015).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rnow'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install rnow
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Connections
|
28
|
+
An instance of the `Rnow::Connection` class is necessary:
|
29
|
+
```ruby
|
30
|
+
connection = Rnow::Connection.new(username: '', password: '', host: '')
|
31
|
+
connection.get(uri, params)
|
32
|
+
```
|
33
|
+
For example:
|
34
|
+
```ruby
|
35
|
+
uri = Rnow::base_path + 'organizations'
|
36
|
+
JSON.parse(connection.get(uri).body)
|
37
|
+
```
|
38
|
+
|
39
|
+
To debug connections:
|
40
|
+
```ruby
|
41
|
+
logger = Logger.new(STDOUT)
|
42
|
+
connection = Rnow::Connection.new(username: '', password: '', host: '', logger: logger)
|
43
|
+
uri = Rnow::base_path + 'organizations'
|
44
|
+
JSON.parse(connection.get(uri).body).map do |item|
|
45
|
+
puts item
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
### Resources
|
50
|
+
The resource object Rnow::Resource can be used raw similar to connection above or can be encapsulated by a higher level Resource object. To use the objects bundled with Gem:
|
51
|
+
|
52
|
+
orgs = Rnow::Organizations.all(connection)
|
53
|
+
|
54
|
+
You can create an incident like this:
|
55
|
+
incident =Rnow::Incident.new(assignedTo: {account: {id: 356}}, category: {id: 2314}, primaryContact: {id: 58599}, organization: {id: 38277}, product: {id: 2740}, severity: {id: 2}, subject: "Test Message 1 Soheil Eizadi", connection: connection).create
|
56
|
+
|
57
|
+
## Development / testing
|
58
|
+
|
59
|
+
Clone:
|
60
|
+
```
|
61
|
+
$ git clone https://github.com/seizadi/rnow.git
|
62
|
+
```
|
63
|
+
|
64
|
+
Bundle:
|
65
|
+
```
|
66
|
+
$ bundle install
|
67
|
+
```
|
68
|
+
|
69
|
+
Make changes and add additional test suite as needed.
|
70
|
+
|
71
|
+
Run the tests:
|
72
|
+
```
|
73
|
+
$ rspec
|
74
|
+
```
|
75
|
+
|
76
|
+
## References
|
77
|
+
|
78
|
+
This is a very early feature for Oracle RightNow and with every release it gets more complete, it took from May to
|
79
|
+
Novemember release to get paging into the mix:
|
80
|
+
http://documentation.custhelp.com/euf/assets/devdocs/november2015/Connect_REST_API/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Connect_REST_API.1.32.html#
|
81
|
+
|
82
|
+
At this time I am running on the August release:
|
83
|
+
Oracle RightNow REST interface documented here:
|
84
|
+
http://documentation.custhelp.com/euf/assets/devdocs/august2015/Connect_REST_API/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Connect_REST_API.1.01.html
|
85
|
+
|
86
|
+
Hoping to test on the Feb 2016 release next, you can monitor the RightNow release train here:
|
87
|
+
http://cxdeveloper.com/page/cx-features-version
|
88
|
+
|
89
|
+
The August release introduced the primitive ROQL interface from REST, it is the only way to properly do searching and paganition support until the REST interface is complete.
|
90
|
+
http://documentation.custhelp.com/euf/assets/devdocs/november2015/Connect_REST_API/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Connect_REST_API.1.29.html
|
91
|
+
|
92
|
+
The design pattern for this Gem is based on previous work by Billy Reisinger, https://github.com/govdelivery/infoblox.git
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it ( https://github.com/[my-github-username]/rnow/fork )
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/rnow.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'json'
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'openssl'
|
6
|
+
require "rnow/version"
|
7
|
+
require "rnow/connection"
|
8
|
+
require "rnow/resource"
|
9
|
+
# Require everything in the resources directory
|
10
|
+
Dir[File.expand_path('../rnow/resources/*.rb', __FILE__)].each do |f|
|
11
|
+
require f
|
12
|
+
end
|
13
|
+
|
14
|
+
module Rnow
|
15
|
+
DEBUG = ENV['DEBUG']
|
16
|
+
|
17
|
+
def rnow_version
|
18
|
+
@rnow_version ||= (ENV['RNOW_VERSION'] || '1.3')
|
19
|
+
end
|
20
|
+
module_function :rnow_version
|
21
|
+
|
22
|
+
def rnow_version=(v)
|
23
|
+
@rnow_version = v
|
24
|
+
end
|
25
|
+
module_function :rnow_version=
|
26
|
+
|
27
|
+
def base_path
|
28
|
+
'services/rest/connect/v' + Rnow.rnow_version + '/'
|
29
|
+
end
|
30
|
+
module_function :base_path
|
31
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Rnow
|
2
|
+
class Error < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class ClearTextEncoder
|
6
|
+
def self.encode(params)
|
7
|
+
buffer = ''
|
8
|
+
params.each do |key, value|
|
9
|
+
buffer << "#{key}=#{value}&"
|
10
|
+
end
|
11
|
+
return buffer.chop
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Connection
|
16
|
+
attr_accessor :adapter,
|
17
|
+
:adapter_block,
|
18
|
+
:connection,
|
19
|
+
:host,
|
20
|
+
:logger,
|
21
|
+
:password,
|
22
|
+
:ssl_opts,
|
23
|
+
:username
|
24
|
+
|
25
|
+
def get(href, params={})
|
26
|
+
wrap do
|
27
|
+
connection.get(href, params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def post(href, body)
|
32
|
+
wrap do
|
33
|
+
connection.post do |req|
|
34
|
+
req.url href
|
35
|
+
req.body = body.to_json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def put(href, body)
|
41
|
+
wrap do
|
42
|
+
connection.put do |req|
|
43
|
+
req.url href
|
44
|
+
req.body = body.to_json
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete(href)
|
50
|
+
wrap do
|
51
|
+
connection.delete(href)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(opts={})
|
56
|
+
self.username = opts[:username]
|
57
|
+
self.password = opts[:password]
|
58
|
+
self.host = opts[:host]
|
59
|
+
self.logger = opts[:logger]
|
60
|
+
self.ssl_opts = opts[:ssl_opts]
|
61
|
+
end
|
62
|
+
|
63
|
+
def connection
|
64
|
+
@connection ||= Faraday.new(:url => self.host, :ssl => {:verify => false}) do |faraday|
|
65
|
+
faraday.use Faraday::Response::Logger, logger if logger
|
66
|
+
faraday.request :json
|
67
|
+
faraday.basic_auth(self.username, self.password)
|
68
|
+
faraday.adapter(self.adapter, &self.adapter_block)
|
69
|
+
faraday.options.params_encoder = Rnow::ClearTextEncoder # Used for ROQL encoding
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# The host variable is expected to be a protocol with a host name.
|
75
|
+
# If the host has no protocol, https:// is added before it.
|
76
|
+
#
|
77
|
+
def host=(new_host)
|
78
|
+
unless new_host =~ /^http(s)?:\/\//
|
79
|
+
new_host = "https://#{new_host}"
|
80
|
+
end
|
81
|
+
@host = new_host
|
82
|
+
end
|
83
|
+
|
84
|
+
def adapter
|
85
|
+
@adapter ||= :net_http
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Don't display the username/password in logging, etc.
|
90
|
+
#
|
91
|
+
def inspect
|
92
|
+
"#<#{self.class}:#{object_id} @host=\"#{@host}\">"
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def wrap
|
98
|
+
yield.tap do |response|
|
99
|
+
unless response.status < 300
|
100
|
+
raise Rnow::Error.new("Error: #{response.status} #{response.body}")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|