uptrends_extended 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +23 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +9 -0
- data/examples/add_new_probes.rb +71 -0
- data/examples/add_probes_to_probe_group.rb +26 -0
- data/examples/get_checkpoint_ips.rb +12 -0
- data/examples/update_all_probe_attributes.rb +17 -0
- data/lib/uptrends_extended.rb +3 -0
- data/lib/uptrends_extended/api_error.rb +4 -0
- data/lib/uptrends_extended/base.rb +121 -0
- data/lib/uptrends_extended/checkpoint.rb +36 -0
- data/lib/uptrends_extended/client.rb +82 -0
- data/lib/uptrends_extended/probe.rb +32 -0
- data/lib/uptrends_extended/probe_group.rb +48 -0
- data/lib/uptrends_extended/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/GET_Checkpoints.yml +373 -0
- data/spec/fixtures/vcr_cassettes/GET_Probe.yml +44 -0
- data/spec/fixtures/vcr_cassettes/GET_Probe_Group.yml +43 -0
- data/spec/fixtures/vcr_cassettes/GET_Probe_Groups.yml +49 -0
- data/spec/fixtures/vcr_cassettes/GET_Probes.yml +289 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/uptrends_extended/client_spec.rb +191 -0
- data/spec/uptrends_extended/probe_group_spec.rb +43 -0
- data/spec/uptrends_extended/probe_spec.rb +47 -0
- data/uptrends_extended.gemspec +25 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjM1MTE1NWJkOGE5ZmI3N2U4N2FjNzFjNWUzYmMyNjFlMjQzZTQ4Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDE4ZmZiNGEwMjMxMTU4NDdhNmE0ZDBiOTEzYjAzMjI3NDY3MjBlMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTZmNjZkMGJmZTIxNDAxN2E5NzM3NDJjZDk3OGI2NzU3YTQ3ZTA0YzBiZDQy
|
10
|
+
YjY0ZDM4ZWY2MGQxMTA5MTIxZWM0YjgyNTI2YmY4YWE3YzMwOGFhNjQ5Nzhi
|
11
|
+
NGFjMThmYzkwYWRhZWY0MTIyNzJmZGFhZWI0NGNiMmYyNjRlNWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTBiYTgwYjk0NGY1NmZhZGU0NzIzYjgzNThhN2IwNmE0NWU1ZDJjMzczZDEw
|
14
|
+
YjFlZjhhN2M2NTJhZWQ0ODNmZjg4YzJkZDU1YmUxMWRmNDg1YzBhMzdiNzUx
|
15
|
+
Yjg0OTc0ZTIyNjg1ODVmNDZlN2I5MzEwZWUyZDkwYWIzYjAyNjM=
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.idea
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# UptrendsExtended Gem Changelog
|
2
|
+
|
3
|
+
## 0.7.0
|
4
|
+
- Added the statistics part, so you are able to get statistics about probes and probegroups
|
5
|
+
- Minor syntax fixes for rails 3 and up
|
6
|
+
|
7
|
+
## 0.6.0
|
8
|
+
- Completely redesigned the UptrendsExtended::Client class to make it more idiomatic.
|
9
|
+
- Completely redesigned the UptrendsExtended::Base class to make it more idiomatic.
|
10
|
+
- Added #create!, #update! and #delete! methods to UptrendsExtended::Base
|
11
|
+
- Added #enable, #disable, #enable_alerts and #disable_alerts methods to UptrendsExtended::Probe
|
12
|
+
- Added #add_probe, #remove_probe and #members methods to UptrendsExtended::ProbeGroup
|
13
|
+
- Removed UptrendsExtended::Utils class
|
14
|
+
|
15
|
+
## 0.5.0
|
16
|
+
- Added UptrendsExtended::Monitor class.
|
17
|
+
- Added UptrendsExtended::Client#monitors method to fetch all monitors.
|
18
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in uptrends_extended.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'httparty', '~> 0.13'
|
7
|
+
gem 'activesupport', '~> 03.2.13'
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'webmock'
|
11
|
+
gem 'vcr'
|
12
|
+
gem 'rake'
|
13
|
+
gem 'codeclimate-test-reporter', require: nil
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014-2015 Jason Barnett
|
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,60 @@
|
|
1
|
+
# Uptrends RESTful API Client
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/microting/uptrends-gem/badges/gpa.svg)](https://codeclimate.com/github/microting/uptrends-gem) [![Test Coverage](https://codeclimate.com/github/microting/uptrends-gem/badges/coverage.svg)](https://codeclimate.com/github/microting/uptrends-gem/coverage) [![Build Status](https://travis-ci.org/microting/uptrends-gem.svg)](https://travis-ci.org/microting/uptrends-gem) [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/microting/uptrends-gem/blob/master/LICENSE.txt)
|
4
|
+
|
5
|
+
This is a ruby wrapper around the [Uptrends API][2]. Uptrends is a monitoring service that let's you monitor Web pages, Web services, Mail servers, Database servers, DNS, SSL certificates, FTP and more.
|
6
|
+
|
7
|
+
NOTE: This is a 3rd party gem and not an official product from Uptrends.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'uptrends_extended'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install uptrends_extended
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
require 'uptrends_extended'
|
26
|
+
u = UptrendsExtended::Client.new(username: 'my@email.com', password: 'MyP@sswo0rd') #=> #<UptrendsExtended::Client>
|
27
|
+
|
28
|
+
probes = u.probes #=> [#<UptrendsExtended::Probe>, #<UptrendsExtended::Probe>, ...]
|
29
|
+
p = probes.first #=> #<UptrendsExtended::Probe>
|
30
|
+
p.attributes #=> [:guid, :name, :url, :port, :check_frequency, :probe_type, :is_active, :generate_alert, :notes, :performance_limit1, :performance_limit2, :error_on_limit1, :error_on_limit2, :min_bytes, :error_on_min_bytes, :timeout, :tcp_connect_timeout, :match_pattern, :dns_lookup_mode, :user_agent, :user_name, :password, :is_competitor, :checkpoints, :http_method, :post_data]
|
31
|
+
p.guid #=> "7ef43a1b255949f5a052444348971690"
|
32
|
+
p.name #=> "My Probe's Name"
|
33
|
+
p.statistics('2015/01/01', '2015/12/31', 'Year') #=> [{"Dimension"=>"2015", "Alerts"=>0, "SLAPercentage"=>99.8, "SLATotalTime"=>2, "SLAOperatorResponseTime"=>15, "AvgOperatorResponseTime"=>0, "PercentageOK"=>99.82507, "PercentageError"=>0.1749256, "PercentageUnknown"=>0, "PercentageUptime"=>99.82507, "TotalChecks"=>3168, "Errors"=>5, "UnconfirmedErrors"=>12, "SecondsOK"=>1893489, "SecondsError"=>3318, "SecondsUnknown"=>0, "AverageTotalTime"=>1.229745, "AverageResolveTime"=>0.1484861, "AverageConnectionTime"=>0.1247686, "AverageDownloadTime"=>0.9560824, "AverageTotalBytes"=>6961}]
|
34
|
+
p.uptime_this_year #=> {:sla=>99.8, :uptime=>99.82507}
|
35
|
+
p.uptime_last_12_month #=> {:sla=>99.8, :uptime=>99.82158}
|
36
|
+
|
37
|
+
probe_groups = u.probe_groups #=> [#<UptrendsExtended::ProbeGroup>, #<UptrendsExtended::ProbeGroup>, ... ]
|
38
|
+
pg = probe_groups.first #=> #<UptrendsExtended::ProbeGroup>
|
39
|
+
pg.attributes #=> [:guid, :name, :is_all, :is_client_probe_group]
|
40
|
+
pg.guid #=> "c8d6a0f704494c37823850f3d4fd4273"
|
41
|
+
pg.name #=> "All probes"
|
42
|
+
|
43
|
+
# Let's change the name of the probe:
|
44
|
+
p.name = "My Probe's NEW name" #=> "My Probe's NEW name"
|
45
|
+
p.update! #=> nil
|
46
|
+
|
47
|
+
# Let's add our probe to our probe group
|
48
|
+
pg.add_probe(p) #=> [#<UptrendsExtended::ProbeGroup>, #<UptrendsExtended::Probe>]
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( https://github.com/microting/uptrends-gem/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create a new Pull Request
|
57
|
+
|
58
|
+
|
59
|
+
[1]: https://uptrends.com/
|
60
|
+
[2]: http://www.uptrends.com/en/support/api
|
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'uptrends_extended/client'
|
3
|
+
require 'uri'
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
def parse_uri_for_db(url)
|
7
|
+
begin
|
8
|
+
uri = URI(url)
|
9
|
+
Rack::Utils.parse_query(uri.query)['dbname'].downcase
|
10
|
+
rescue URI::InvalidURIError
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_uri(url)
|
16
|
+
begin
|
17
|
+
uri = URI(url)
|
18
|
+
"#{uri.scheme}://#{uri.host}".downcase
|
19
|
+
rescue URI::InvalidURIError
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
(puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
|
25
|
+
|
26
|
+
u = UptrendsExtended::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
|
27
|
+
|
28
|
+
filename = ARGV.first
|
29
|
+
site_urls = File.open(filename)
|
30
|
+
site_urls = site_urls.readlines.map { |x| x.delete("\n") }.compact
|
31
|
+
|
32
|
+
# Build array of URLs to possibly add to Uptrends
|
33
|
+
uri_array = site_urls.map do |url|
|
34
|
+
uri = parse_uri(url)
|
35
|
+
db = parse_uri_for_db(url)
|
36
|
+
next unless uri && db
|
37
|
+
[uri, db]
|
38
|
+
end.compact.uniq
|
39
|
+
|
40
|
+
# Build array of Uptrends Probe URLs that already exist
|
41
|
+
probe_uri_array = u.probes.map do |x|
|
42
|
+
next unless x.probe_type =~ /Https?/
|
43
|
+
parse_uri(x.url)
|
44
|
+
end.compact
|
45
|
+
|
46
|
+
uri_array.each do |uri|
|
47
|
+
url = uri[0]
|
48
|
+
db = uri[1]
|
49
|
+
|
50
|
+
# If URL contains certain things we don't want to add it Uptrends
|
51
|
+
next if url =~ /\.xxx/i ||
|
52
|
+
url =~ /backup/i ||
|
53
|
+
url =~ /clusterbogota/i ||
|
54
|
+
url =~ /archive/i ||
|
55
|
+
url =~ /thebigawards/i ||
|
56
|
+
url =~ /staging/i ||
|
57
|
+
url =~ /qa(languages)?[0-9gaspb]+(prod)?\./i
|
58
|
+
# If the URL already exists at Uptrends we don't want to add it again!
|
59
|
+
next if probe_uri_array.include?(url)
|
60
|
+
|
61
|
+
url = "#{uri[0]}/User/Login"
|
62
|
+
db = uri[1]
|
63
|
+
|
64
|
+
puts "Adding a \"#{url}\" probe"
|
65
|
+
begin
|
66
|
+
new_probe = u.create_http_probe(name: db, url: url, match_pattern: 'j_username')
|
67
|
+
rescue UptrendsExtended::ApiError => e
|
68
|
+
puts e.message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'uptrends_extended'
|
3
|
+
|
4
|
+
(puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
|
5
|
+
|
6
|
+
u = UptrendsExtended::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
|
7
|
+
|
8
|
+
# select our probe group by name
|
9
|
+
linux_probe_group = u.probe_groups.select { |x| x.name =~ /Linux/}.first
|
10
|
+
|
11
|
+
# grab the current group members
|
12
|
+
linux_group_members = u.get_probe_group_members(group: linux_probe_group)
|
13
|
+
|
14
|
+
# build an array of current probe group members guid
|
15
|
+
member_guids = linux_group_members.inject([]) do |memo, x|
|
16
|
+
memo << x.guid
|
17
|
+
memo
|
18
|
+
end
|
19
|
+
|
20
|
+
# add any missing probes to our probe group
|
21
|
+
u.probes.each do |x|
|
22
|
+
next if member_guids.include?(x.guid)
|
23
|
+
|
24
|
+
puts "Adding \"#{x.name}\" to the \"#{linux_probe_group.name}\" group now... "
|
25
|
+
u.add_probe_to_group(probe: x, group: linux_probe_group)
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "uptrends_extended"
|
3
|
+
require "ipaddr"
|
4
|
+
|
5
|
+
(puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
|
6
|
+
|
7
|
+
u = UptrendsExtended::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
|
8
|
+
checkpoint_ips = u.checkpoints.inject([]) { |memo,x| memo << x.ip_address; memo }.sort_by { |x| IPAddr.new(x) }
|
9
|
+
|
10
|
+
checkpoint_ips.each do |ip|
|
11
|
+
puts "allow #{ip};"
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'uptrends_extended/client'
|
3
|
+
|
4
|
+
(puts "You must set both the \"UPTRENDS_USERNAME\" and \"UPTRENDS_PASSWORD\" environment variables, exiting..."; exit 1;) unless ENV['UPTRENDS_USERNAME'] && ENV['UPTRENDS_PASSWORD']
|
5
|
+
|
6
|
+
u = UptrendsExtended::Client.new(username: ENV['UPTRENDS_USERNAME'], password: ENV['UPTRENDS_PASSWORD'])
|
7
|
+
|
8
|
+
u.probes.each do |x|
|
9
|
+
next if x.dns_lookup_mode == 'Local' && x.timeout == 20000 && x.tcp_connect_timeout == 5000
|
10
|
+
|
11
|
+
x.dns_lookup_mode = 'Local'
|
12
|
+
x.timeout = 20000
|
13
|
+
x.tcp_connect_timeout = 5000
|
14
|
+
|
15
|
+
puts "Updating the \"#{x.name}\" probe now... "
|
16
|
+
u.update_probe(x)
|
17
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'uptrends_extended/api_error'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
module UptrendsExtended
|
6
|
+
class Base
|
7
|
+
|
8
|
+
attr_reader :attributes
|
9
|
+
|
10
|
+
def initialize(client, response, attributes = {})
|
11
|
+
@client = client
|
12
|
+
@attributes = attributes
|
13
|
+
gen_and_set_accessors
|
14
|
+
end
|
15
|
+
|
16
|
+
def create!
|
17
|
+
response = @client.class.post(api_url, body: gen_request_body)
|
18
|
+
self.class.parse(@client, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update!
|
22
|
+
response = @client.class.put("#{api_url}/#{@guid}", body: gen_request_body)
|
23
|
+
self.class.check_error!(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete!
|
27
|
+
response = @client.class.delete("#{api_url}/#{@guid}")
|
28
|
+
self.class.check_error!(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.check_error!(response)
|
32
|
+
response_code = response.response.code.to_i
|
33
|
+
case response_code
|
34
|
+
when 200...300
|
35
|
+
response.parsed_response
|
36
|
+
else
|
37
|
+
raise UptrendsExtended::ApiError.new(response.parsed_response)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param [yyyy/mm/dd] start_of_period
|
42
|
+
# @param [yyyy/mm/dd] end_of_period
|
43
|
+
# @param [Day, Week, Month, Year, ProbeGroup, Probe, Checkpoint, ErrorCode, ErrorLevel] dimension
|
44
|
+
def statistics(start_of_period, end_of_period, dimension)
|
45
|
+
response = @client.class.get("#{api_url}/#{@guid}/statistics?Start=#{start_of_period}&End=#{end_of_period}&Dimension=#{dimension}", body: gen_request_body)
|
46
|
+
self.class.check_error!(response)
|
47
|
+
end
|
48
|
+
|
49
|
+
def uptime_this_year
|
50
|
+
stats = statistics("#{Time.now.year}/01/01", "#{Time.now.year}/12/31", 'Year')
|
51
|
+
{sla: stats[0]['SLAPercentage'], uptime: stats[0]['PercentageUptime']}
|
52
|
+
end
|
53
|
+
|
54
|
+
def uptime_last_12_months
|
55
|
+
start_period = Time.now - 12.months
|
56
|
+
stats = statistics(start_period.strftime('%Y/%m/%d'), Time.now.strftime('%Y/%m/%d'), 'Year')
|
57
|
+
{sla: stats[0]['SLAPercentage'], uptime: stats[0]['PercentageUptime']}
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.parse(client, response)
|
61
|
+
check_error!(response)
|
62
|
+
parsed_response = response.parsed_response
|
63
|
+
if Array === parsed_response
|
64
|
+
parsed_response.map do |item|
|
65
|
+
new(client, response, item)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
new(client, response, parsed_response)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s
|
73
|
+
string = []
|
74
|
+
attributes.each do |attr|
|
75
|
+
string << "#{attr}: #{self.send(attr)}"
|
76
|
+
end
|
77
|
+
|
78
|
+
"#{string.join("\n")}"
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# This method sets up all of our attr_accessor so we can easily edit probe attributes
|
84
|
+
def gen_and_set_accessors
|
85
|
+
attributes = []
|
86
|
+
self.attributes.each_pair do |k,v|
|
87
|
+
|
88
|
+
k = k.to_s.underscore
|
89
|
+
case k
|
90
|
+
when 'guid'
|
91
|
+
# setup attr_reader for guid and set it's value.
|
92
|
+
self.class.send(:attr_reader, k)
|
93
|
+
self.instance_variable_set("@#{k}", v)
|
94
|
+
else
|
95
|
+
# setup a attr_accessor for all other attributes
|
96
|
+
self.class.send(:attr_accessor, k)
|
97
|
+
self.send("#{k}=", v)
|
98
|
+
end
|
99
|
+
attributes << k.to_sym
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
@attributes = attributes
|
104
|
+
end
|
105
|
+
|
106
|
+
def gen_request_body
|
107
|
+
new_hash = @attributes.inject({}) do |memo,(k,v)|
|
108
|
+
if k.to_s.underscore == 'guid'
|
109
|
+
memo
|
110
|
+
else
|
111
|
+
memo[k.to_s.camelize] = self.send(k.to_s.underscore)
|
112
|
+
memo
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
request_body = JSON.dump(new_hash)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|