netdnarws 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.
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+ *.gem
17
+ *.lock
18
+
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ #.DS_Store
33
+
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+
38
+ # For emacs:
39
+ #*~
40
+ #\#*
41
+ #.\#*
42
+
43
+ # For vim:
44
+ #*.swp
45
+
46
+ # For redcar:
47
+ #.redcar
48
+
49
+ # For rubinius:
50
+ #*.rbc
data/.rvmrc ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3@netdnarws"
8
+
9
+ #
10
+ # First we attempt to load the desired environment directly from the environment
11
+ # file. This is very fast and efficicent compared to running through the entire
12
+ # CLI and selector. If you want feedback on which environment was used then
13
+ # insert the word 'use' after --create as this triggers verbose mode.
14
+ #
15
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
16
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
17
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
18
+ else
19
+ # If the environment file has not yet been created, use the RVM CLI to select.
20
+ rvm --create use "$environment_id"
21
+ fi
22
+
23
+ #
24
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
25
+ # it be automatically loaded. Uncomment the following and adjust the filename if
26
+ # necessary.
27
+ #
28
+ # filename=".gems"
29
+ # if [[ -s "$filename" ]] ; then
30
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
31
+ # fi
32
+
33
+ #
34
+ # If you use bundler and would like to run bundle each time you enter the
35
+ # directory, you can uncomment the following code.
36
+ #
37
+ # # Ensure that Bundler is installed. Install it if it is not.
38
+ # if ! command -v bundle >/dev/null; then
39
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
40
+ # gem install bundler
41
+ # fi
42
+ #
43
+ # # Bundle while reducing excess noise.
44
+ # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
45
+ # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
46
+ #
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "oauth"
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Litvak Bruno
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,24 @@
1
+ # NetDNA REST Web Services Ruby Client
2
+
3
+ ## Installation
4
+ `gem install netdnarws`
5
+
6
+ ## Usage
7
+ ```ruby
8
+ require 'netdnarws'
9
+
10
+ api = NetDNARWS::NetDNA.new("myalias", "consumer_key", "consumer_secret")
11
+
12
+ api.get("/account.json")
13
+ ```
14
+
15
+ ## Methods
16
+ It has support for GET, POST, PUT and DELETE ouath signed requests.
17
+
18
+ Every request can take an optional debug parameter.
19
+ ```ruby
20
+ api.get("/account.json", debug=True)
21
+ # Will output
22
+ # Making GET request to http://rws.netdna.com/myalias/account.json
23
+ #{... API Returned Stuff ...}
24
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,3 @@
1
+ module NetDNARWS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/netdnarws.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'oauth'
2
+ require 'json'
3
+
4
+ module NetDNARWS
5
+ class NetDNA
6
+ attr_accessor :client
7
+ def initialize company_alias, key, secret,
8
+ server='rws.netdna.com', secure_connection=true, *options
9
+ @company_alias = company_alias
10
+ @server = server
11
+ @secure_connection = secure_connection
12
+ @client = OAuth::Consumer.new(key, secret,
13
+ :site => "#{_connection_type}://#{server}")
14
+ end
15
+
16
+ def _connection_type
17
+ return "http" unless @secure_connection
18
+ "https"
19
+ end
20
+
21
+ def _get_url uri
22
+ "#{_connection_type}://#{@server}/#{@company_alias}#{uri}"
23
+ end
24
+
25
+ def _response_as_json method, uri, options={}, *attributes
26
+ if options.delete(:debug)
27
+ puts "Making #{method.upcase} request to #{_get_url uri}"
28
+ end
29
+
30
+ response = @client.request method, _get_url(uri), nil, options, attributes
31
+ begin
32
+ response_json = JSON.parse(response.body)
33
+ if response.code != "200"
34
+ error_message = response_json['error']['message']
35
+ raise Exception.new("#{response.code}: #{error_message}")
36
+ end
37
+ rescue TypeError
38
+ raise Exception.new(
39
+ "#{response.code}: No information supplied by the server"
40
+ )
41
+ end
42
+
43
+ response_json
44
+ end
45
+
46
+ def get uri, options={}
47
+ self._response_as_json 'get', uri, options
48
+ end
49
+
50
+ def post uri, data={}, options={}
51
+ self._response_as_json 'post', uri, options, [data]
52
+ end
53
+
54
+ def put uri, data={}, options={}
55
+ self._response_as_json 'put', uri, options, [data]
56
+ end
57
+
58
+ def delete uri, options={}
59
+ self._response_as_json 'delete', uri, options
60
+ end
61
+ end
62
+ end
data/netdnarws.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/netdnarws/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "netdnarws"
6
+ gem.homepage = "http://developer.netdna.com"
7
+ gem.version = NetDNARWS::VERSION
8
+ gem.license = "MIT"
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.require_paths = ['lib']
11
+ gem.summary = %Q{A Rest Client For NetDNA Rest Web Services}
12
+ gem.description = %Q{A Rest Client For NetDNA Rest Web Services}
13
+ gem.email = "devteam@netdna.com"
14
+ gem.authors = ["NetDNA Developer Team"]
15
+ gem.add_dependency 'oauth'
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netdnarws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - NetDNA Developer Team
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A Rest Client For NetDNA Rest Web Services
31
+ email: devteam@netdna.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - .rvmrc
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - VERSION
43
+ - lib/netdnarws.rb
44
+ - lib/netdnarws/version.rb
45
+ - netdnarws.gemspec
46
+ homepage: http://developer.netdna.com
47
+ licenses:
48
+ - MIT
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.21
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A Rest Client For NetDNA Rest Web Services
71
+ test_files: []