shanesveller-webbynode-api 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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Shane Sveller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = webbynode-api
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Shane Sveller. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "webbynode-api"
8
+ gem.summary = "wraps the WebbyNode API into nice Ruby objects"
9
+ gem.email = "shanesveller@gmail.com"
10
+ gem.homepage = "http://github.com/shanesveller/webbynode-api"
11
+ gem.authors = ["Shane Sveller"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "webbynode-api #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ gem 'httparty'
3
+ require 'httparty'
4
+
5
+ class WebbyNode
6
+ class Client
7
+ include HTTParty
8
+ base_uri "https://manager.webbynode.com"
9
+ format :xml
10
+
11
+ attr_accessor :email, :api_key, :data
12
+
13
+ def initialize(email, api_key)
14
+ @email = email
15
+ @api_key = api_key
16
+ @data = self.auth_get('/api/xml/client')["hash"]["client"]
17
+ end
18
+
19
+ def auth_get(url, options = {})
20
+ options[:query] ||= {}
21
+ options[:query].merge!(:email => @email, :token => @api_key)
22
+ self.class.get(url, options)
23
+ end
24
+
25
+ def method_missing(method)
26
+ key = @data[method.to_s]
27
+ key
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <hash>
3
+ <client>
4
+ <city>Nameless City</city>
5
+ <address1>1234 Nonexistent Lane</address1>
6
+ <country>US</country>
7
+ <postcode>65432</postcode>
8
+ <phonenumber>555-867-5309</phonenumber>
9
+ <credit type="decimal">1.5</credit>
10
+ <lastname>Sveller</lastname>
11
+ <datecreated type="date">2009-06-30</datecreated>
12
+ <firstname>Shane</firstname>
13
+ <status>Active</status>
14
+ <state>My State</state>
15
+ <email>example@email.com</email>
16
+ <companyname>Phantom Inc.</companyname>
17
+ </client>
18
+ </hash>
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ %w(matchy fakeweb pp).each {|x| require x }
5
+
6
+ FakeWeb.allow_net_connect = false
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'webbynode-api'
11
+
12
+ class Test::Unit::TestCase
13
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class WebbynodeApiTest < Test::Unit::TestCase
4
+ context "fetching client data from API" do
5
+ setup do
6
+ email = "example@email.com"
7
+ api_key = "123456"
8
+ data_path = File.join(File.dirname(__FILE__), "data")
9
+ FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/api-xml-client.xml"))
10
+ @api = WebbyNode::Client.new(email, api_key)
11
+ end
12
+
13
+ should "use method missing to get values for present keys" do
14
+ @api.methods.include?("firstname").should == false
15
+ @api.firstname.should == "Shane"
16
+ end
17
+
18
+ should "return nil for missing keys" do
19
+ @api.blank.should be(nil)
20
+ end
21
+
22
+ should "fetch physical address information" do
23
+ @api.address1.should == "1234 Nonexistent Lane"
24
+ @api.city.should == "Nameless City"
25
+ @api.postcode.should == "65432"
26
+ @api.state.should == "My State"
27
+ @api.country.should == "US"
28
+ end
29
+
30
+ should "fetch user name, email and status" do
31
+ @api.firstname.should == "Shane"
32
+ @api.lastname.should == "Sveller"
33
+ @api.email.should == "example@email.com"
34
+ @api.status.should == "Active"
35
+ @api.datecreated.should == Date.new(2009,06,30)
36
+ end
37
+
38
+ should "fetch company name, phone number and credits" do
39
+ @api.credit.should == 1.5
40
+ @api.companyname.should == "Phantom Inc."
41
+ @api.phonenumber.should == "555-867-5309"
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shanesveller-webbynode-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shane Sveller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: shanesveller@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/webbynode-api.rb
33
+ - test/data/api-xml-client.xml
34
+ - test/test_helper.rb
35
+ - test/webbynode-api_test.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/shanesveller/webbynode-api
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: wraps the WebbyNode API into nice Ruby objects
62
+ test_files:
63
+ - test/test_helper.rb
64
+ - test/webbynode-api_test.rb