whuffiebank 0.1.0
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 +2 -0
- data/History.txt +4 -0
- data/Manifest.txt +12 -0
- data/PostInstall.txt +7 -0
- data/README +0 -0
- data/README.rdoc +48 -0
- data/Rakefile +58 -0
- data/lib/whuffiebank.rb +68 -0
- data/lib/whuffiebank/balance.rb +24 -0
- data/lib/whuffiebank/client.rb +51 -0
- data/lib/whuffiebank/give_response.rb +16 -0
- data/lib/whuffiebank/whuffie.rb +26 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/fixtures/balance.json +1 -0
- data/test/fixtures/balance_error.json +1 -0
- data/test/fixtures/give_whuffie.json +1 -0
- data/test/fixtures/give_whuffie_error.json +1 -0
- data/test/fixtures/whuffie.json +1 -0
- data/test/fixtures/whuffie_error.json +1 -0
- data/test/test_helper.rb +33 -0
- data/test/test_whuffiebank.rb +79 -0
- data/whuffiebank.gemspec +83 -0
- metadata +139 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/History.txt
    ADDED
    
    
    
        data/Manifest.txt
    ADDED
    
    
    
        data/PostInstall.txt
    ADDED
    
    
    
        data/README
    ADDED
    
    | 
            File without changes
         | 
    
        data/README.rdoc
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            == Whuffiebank API Ruby Gem
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * http://github.com/etagwerker/whuffiebank
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            == DESCRIPTION:
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            This gem implements the thewhuffiebank.org API.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             | 
| 10 | 
            +
            == FEATURES:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              >> Whuffiebank.give_whuffie('rtopsy','a_password','etagwerker',10)
         | 
| 13 | 
            +
              => <#Whuffiebank::GiveResponse result="success">
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              >> Whuffiebank.balance('rtopsy','a_password')
         | 
| 16 | 
            +
              => <#Whuffiebank::Balance balance=0 result="success">
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              >> Whuffiebank.whuffie('etagwerker')
         | 
| 19 | 
            +
              => <#Whuffiebank::Whuffie ranking=293464 result="success" username="etagwerker" whuffie=125>
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            == INSTALL:
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              sudo gem install whuffiebank
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            == LICENSE:
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            (The MIT License)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            Copyright (c) 2010 FIXME Ernesto Tagwerker <etagwerker@gmail.com>
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 32 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 33 | 
            +
            'Software'), to deal in the Software without restriction, including
         | 
| 34 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 35 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 36 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 37 | 
            +
            the following conditions:
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 40 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
         | 
| 43 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 44 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         | 
| 45 | 
            +
            IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         | 
| 46 | 
            +
            CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         | 
| 47 | 
            +
            TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         | 
| 48 | 
            +
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,58 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
            require 'rake'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            begin
         | 
| 5 | 
            +
              require 'jeweler'
         | 
| 6 | 
            +
              Jeweler::Tasks.new do |gem|
         | 
| 7 | 
            +
                gem.name = "whuffiebank"
         | 
| 8 | 
            +
                gem.summary = %Q{Ruby wrapper for the Whuffiebank API}
         | 
| 9 | 
            +
                gem.description = %Q{Ruby wrapper for the Whuffiebank API}
         | 
| 10 | 
            +
                gem.email = "etagwerker@gmail.com"
         | 
| 11 | 
            +
                gem.homepage = "http://github.com/etagwerker/whuffiebank"
         | 
| 12 | 
            +
                gem.authors = ["Ernesto Tagwerker"]
         | 
| 13 | 
            +
                
         | 
| 14 | 
            +
                gem.add_dependency('hashie', '~> 0.1.3')
         | 
| 15 | 
            +
                gem.add_dependency('httparty', '~> 0.4.5')
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                gem.add_development_dependency('thoughtbot-shoulda', '>= 2.10.1')
         | 
| 18 | 
            +
                gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
         | 
| 19 | 
            +
                gem.add_development_dependency('mocha', '0.9.4')
         | 
| 20 | 
            +
                gem.add_development_dependency('fakeweb', '>= 1.2.5')
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              Jeweler::GemcutterTasks.new
         | 
| 23 | 
            +
            rescue LoadError
         | 
| 24 | 
            +
              puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            require 'rake/testtask'
         | 
| 28 | 
            +
            Rake::TestTask.new(:test) do |test|
         | 
| 29 | 
            +
              test.libs << 'lib' << 'test'
         | 
| 30 | 
            +
              test.pattern = 'test/**/test_*.rb'
         | 
| 31 | 
            +
              test.verbose = true
         | 
| 32 | 
            +
            end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            begin
         | 
| 35 | 
            +
              require 'rcov/rcovtask'
         | 
| 36 | 
            +
              Rcov::RcovTask.new do |test|
         | 
| 37 | 
            +
                test.libs << 'test'
         | 
| 38 | 
            +
                test.pattern = 'test/**/test_*.rb'
         | 
| 39 | 
            +
                test.verbose = true
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            rescue LoadError
         | 
| 42 | 
            +
              task :rcov do
         | 
| 43 | 
            +
                abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            task :test => :check_dependencies
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            task :default => :test
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            begin
         | 
| 52 | 
            +
              require 'yard'
         | 
| 53 | 
            +
              YARD::Rake::YardocTask.new
         | 
| 54 | 
            +
            rescue LoadError
         | 
| 55 | 
            +
              task :yardoc do
         | 
| 56 | 
            +
                abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
            end
         | 
    
        data/lib/whuffiebank.rb
    ADDED
    
    | @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            directory = File.expand_path(File.dirname(__FILE__))
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            gem 'hashie', '~> 0.1.3'
         | 
| 6 | 
            +
            require 'hashie'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            gem 'httparty', '~> 0.4.5'
         | 
| 9 | 
            +
            require 'httparty'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            module Whuffiebank
         | 
| 12 | 
            +
              VERSION = '0.0.1'
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              class WhuffieError < StandardError
         | 
| 15 | 
            +
                attr_reader :data
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def initialize(data)
         | 
| 18 | 
            +
                  @data = data
         | 
| 19 | 
            +
                  super
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              class RateLimitExceeded < StandardError; end
         | 
| 24 | 
            +
              class Unauthorized      < StandardError; end
         | 
| 25 | 
            +
              class General           < WhuffieError; end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              class Unavailable   < StandardError; end
         | 
| 28 | 
            +
              class InformWhuffiebank < StandardError; end
         | 
| 29 | 
            +
              class NotFound      < StandardError; end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # Returns the balance for a combination of  username and password
         | 
| 32 | 
            +
              #
         | 
| 33 | 
            +
              # @param [String] username
         | 
| 34 | 
            +
              # @param [String] password
         | 
| 35 | 
            +
              # @return [Whuffiebank::Balance]
         | 
| 36 | 
            +
              def self.balance(username,password)
         | 
| 37 | 
            +
                Whuffiebank::Client.new.balance(username,password)
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
              
         | 
| 40 | 
            +
              # Returns the balance for a combination of  username and password
         | 
| 41 | 
            +
              #
         | 
| 42 | 
            +
              # @param [String] username
         | 
| 43 | 
            +
              # @param [String] password
         | 
| 44 | 
            +
              # @param [String] to_username
         | 
| 45 | 
            +
              # @param [String] amount
         | 
| 46 | 
            +
              # @param [Hash] options method options
         | 
| 47 | 
            +
              #   :reason - Why are you giving whuffie to that user?
         | 
| 48 | 
            +
              #   :alert - Send a messages using Twitter just after the payment. 
         | 
| 49 | 
            +
              # @return [Whuffiebank::GiveResponse]
         | 
| 50 | 
            +
              def self.give_whuffie(username,password,to_username,amount,options={})
         | 
| 51 | 
            +
                Whuffiebank::Client.new.give_whuffie(username,password,to_username,amount,options)      
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
              
         | 
| 54 | 
            +
              # Returns the whuffie information for a username
         | 
| 55 | 
            +
              #
         | 
| 56 | 
            +
              # @param [String] username
         | 
| 57 | 
            +
              # @return [Whuffiebank::Whuffie]
         | 
| 58 | 
            +
              def self.whuffie(username)
         | 
| 59 | 
            +
                Whuffiebank::Client.new.whuffie(username)      
         | 
| 60 | 
            +
              end  
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            require File.join(directory, 'whuffiebank', 'balance')
         | 
| 65 | 
            +
            require File.join(directory, 'whuffiebank', 'give_response')
         | 
| 66 | 
            +
            require File.join(directory, 'whuffiebank', 'whuffie')
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            require File.join(directory, 'whuffiebank', 'client')
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module Whuffiebank
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # This is the Balance class for the whuffiebank library. 
         | 
| 4 | 
            +
              # 
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              #   result - 'success' or 'failure'
         | 
| 7 | 
            +
              #
         | 
| 8 | 
            +
              #   reason - if the result is 'failure', the reason why the request failed.
         | 
| 9 | 
            +
              #
         | 
| 10 | 
            +
              #   balance - if the result is 'success', this is the Whuffie Bank user's balance.
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              #   According to the Whuffiebank API doc: http://www.thewhuffiebank.org/static/api
         | 
| 14 | 
            +
              #
         | 
| 15 | 
            +
              class Balance < Hashie::Mash
         | 
| 16 | 
            +
                def to_s
         | 
| 17 | 
            +
                  if result.eql? 'success'
         | 
| 18 | 
            +
                    "Whuffiebank Balance: #{result}, #{balance}"  
         | 
| 19 | 
            +
                  else
         | 
| 20 | 
            +
                    "Whuffiebank Balance: #{result}, #{reason}"
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            module Whuffiebank
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              class Client
         | 
| 4 | 
            +
                include HTTParty
         | 
| 5 | 
            +
                format :json
         | 
| 6 | 
            +
                base_uri "http://thewhuffiebank.org/api"
         | 
| 7 | 
            +
                
         | 
| 8 | 
            +
                def balance(username,password)
         | 
| 9 | 
            +
                  response = handle_response(self.class.get("/balance/", :query => {:username => username, :password => password}))
         | 
| 10 | 
            +
                  Whuffiebank::Balance.new(response)  
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                def give_whuffie(username,password,to_username,amount,options={})
         | 
| 14 | 
            +
                  response = handle_response(self.class.post("/give/", :body => {:username => username, :password => password, :to => to_username, :amount => amount}))
         | 
| 15 | 
            +
                  Whuffiebank::GiveResponse.new(response)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                def whuffie(username)
         | 
| 19 | 
            +
                  response = handle_response(self.class.get("/whuffie/", :query => {:username => username} ))
         | 
| 20 | 
            +
                  Whuffiebank::Whuffie.new(response)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def handle_response(response)
         | 
| 26 | 
            +
                    raise_errors(response)
         | 
| 27 | 
            +
                    mashup(response)
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                  
         | 
| 30 | 
            +
                  def mashup(response)
         | 
| 31 | 
            +
                    Hashie::Mash.new(response)
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
                  def raise_errors(response)
         | 
| 35 | 
            +
                    code = response.code.to_i
         | 
| 36 | 
            +
                    case code
         | 
| 37 | 
            +
                    when 400
         | 
| 38 | 
            +
                      raise Whuffiebank::General.new("Parameter check failed. This error indicates that a required parameter is missing or a parameter has a value that is out of bounds.")
         | 
| 39 | 
            +
                    when 403
         | 
| 40 | 
            +
                      raise Whuffiebank::Unauthorized.new
         | 
| 41 | 
            +
                    when 404
         | 
| 42 | 
            +
                      raise Whuffiebank::NotFound.new
         | 
| 43 | 
            +
                    when 500
         | 
| 44 | 
            +
                      raise Whuffiebank::InformWhuffiebank.new
         | 
| 45 | 
            +
                    when 503
         | 
| 46 | 
            +
                      raise Whuffiebank::Unavailable.new
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
                 end
         | 
| 49 | 
            +
                
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module Whuffiebank
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # This is the url_info class for the topsy library. 
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              # result - 'success' or 'failure'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # reason - if the result is 'failure', the reason why the request failed.
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              # According to the Whuffiebank API doc: http://www.thewhuffiebank.org/static/api
         | 
| 10 | 
            +
              #
         | 
| 11 | 
            +
              class GiveResponse < Hashie::Mash
         | 
| 12 | 
            +
                def to_s
         | 
| 13 | 
            +
                  "Whuffiebank Response: #{result}. #{reason}"
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            module Whuffiebank
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              # This is the Whuffie class for the whuffiebank library. 
         | 
| 4 | 
            +
              # 
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              #  result - 'success' or 'failure'
         | 
| 7 | 
            +
              #
         | 
| 8 | 
            +
              #  reason - if the result is 'failure', the reason why the request failed.
         | 
| 9 | 
            +
              #
         | 
| 10 | 
            +
              #  whuffie - if the result is 'success', this is the whuffie rate per month.
         | 
| 11 | 
            +
              # 
         | 
| 12 | 
            +
              #  ranking - if the result is 'success', this is the global ranking position.  
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              #  According to the Whuffiebank API doc: http://www.thewhuffiebank.org/static/api
         | 
| 15 | 
            +
              #
         | 
| 16 | 
            +
              class Whuffie < Hashie::Mash
         | 
| 17 | 
            +
                def to_s
         | 
| 18 | 
            +
                  if result.eql? 'success'
         | 
| 19 | 
            +
                    "Whuffiebank Whuffie: #{result}, Whuffie: #{whuffie}"  
         | 
| 20 | 
            +
                  else
         | 
| 21 | 
            +
                    "Whuffiebank Whuffie: #{result}, #{reason}" 
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
    
        data/script/console
    ADDED
    
    | @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # File: script/console
         | 
| 3 | 
            +
            irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            libs =  " -r irb/completion"
         | 
| 6 | 
            +
            # Perhaps use a console_lib to store any extra methods I may want available in the cosole
         | 
| 7 | 
            +
            # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
         | 
| 8 | 
            +
            libs <<  " -r #{File.dirname(__FILE__) + '/../lib/whuffiebank.rb'}"
         | 
| 9 | 
            +
            puts "Loading whuffiebank gem"
         | 
| 10 | 
            +
            exec "#{irb} #{libs} --simple-prompt"
         | 
    
        data/script/destroy
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            begin
         | 
| 5 | 
            +
              require 'rubigen'
         | 
| 6 | 
            +
            rescue LoadError
         | 
| 7 | 
            +
              require 'rubygems'
         | 
| 8 | 
            +
              require 'rubigen'
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
            require 'rubigen/scripts/destroy'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ARGV.shift if ['--help', '-h'].include?(ARGV[0])
         | 
| 13 | 
            +
            RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
         | 
| 14 | 
            +
            RubiGen::Scripts::Destroy.new.run(ARGV)
         | 
    
        data/script/generate
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            begin
         | 
| 5 | 
            +
              require 'rubigen'
         | 
| 6 | 
            +
            rescue LoadError
         | 
| 7 | 
            +
              require 'rubygems'
         | 
| 8 | 
            +
              require 'rubigen'
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
            require 'rubigen/scripts/generate'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ARGV.shift if ['--help', '-h'].include?(ARGV[0])
         | 
| 13 | 
            +
            RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
         | 
| 14 | 
            +
            RubiGen::Scripts::Generate.new.run(ARGV)
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"balance": 126, "result": "success"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"reason": "Invalid twitter username or password", "result": "failure"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"result": "success"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"reason": "Invalid twitter username or password", "result": "failure"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"username": "etagwerker", "ranking": 287842, "whuffie": 126, "result": "success"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"reason": "Whuffie Bank account not found", "result": "failure"}
         | 
    
        data/test/test_helper.rb
    ADDED
    
    | @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require 'stringio'
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require 'pathname'
         | 
| 4 | 
            +
            require File.dirname(__FILE__) + '/../lib/whuffiebank'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'shoulda'
         | 
| 7 | 
            +
            require 'matchy'
         | 
| 8 | 
            +
            require 'mocha'
         | 
| 9 | 
            +
            require 'fakeweb'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            FakeWeb.allow_net_connect = false
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            class Test::Unit::TestCase
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            def fixture_file(filename)
         | 
| 17 | 
            +
              return '' if filename == ''
         | 
| 18 | 
            +
              file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
         | 
| 19 | 
            +
              File.read(file_path)
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            def whuffiebank_url(url)
         | 
| 23 | 
            +
              url =~ /^http/ ? url : "http://thewhuffiebank.org/api#{url}"
         | 
| 24 | 
            +
            end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            def stub_get(url, filename, options={})
         | 
| 27 | 
            +
              opts = {:body => fixture_file(filename)}.merge(options)
         | 
| 28 | 
            +
              FakeWeb.register_uri(:get, whuffiebank_url(url), opts)
         | 
| 29 | 
            +
            end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            def stub_post(url, filename)
         | 
| 32 | 
            +
              FakeWeb.register_uri(:post, whuffiebank_url(url), :body => fixture_file(filename))
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class TestWhuffiebank < Test::Unit::TestCase
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              INVALID_TWITTER_USERNAME = 'Invalid twitter username or password'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              context "when hitting the whuffie bank API" do
         | 
| 8 | 
            +
                
         | 
| 9 | 
            +
                should "return the balance for a whuffie bank member" do
         | 
| 10 | 
            +
                  stub_get("/balance/?username=etagwerker&password=a_password", "balance.json")
         | 
| 11 | 
            +
                  
         | 
| 12 | 
            +
                  balance = Whuffiebank.balance("etagwerker","a_password")
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  balance.class.should == Whuffiebank::Balance
         | 
| 15 | 
            +
                  
         | 
| 16 | 
            +
                  balance.balance.should == 126
         | 
| 17 | 
            +
                  balance.result.should == 'success'
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                should "return a failure because username/password is wrong" do
         | 
| 21 | 
            +
                  stub_get("/balance/?username=etagwerker&password=bad_password", "balance_error.json")
         | 
| 22 | 
            +
                  
         | 
| 23 | 
            +
                  balance = Whuffiebank.balance("etagwerker","bad_password")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  balance.class.should == Whuffiebank::Balance
         | 
| 26 | 
            +
                  
         | 
| 27 | 
            +
                  balance.balance.should == nil
         | 
| 28 | 
            +
                  balance.result.should == 'failure'
         | 
| 29 | 
            +
                  balance.reason.should == INVALID_TWITTER_USERNAME
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                should "give whuffie to a username and return success " do
         | 
| 33 | 
            +
                  stub_post('/give/?', 'give_whuffie.json')
         | 
| 34 | 
            +
                  
         | 
| 35 | 
            +
                  response = Whuffiebank.give_whuffie('etagwerker','a_password','rtopsy',12)
         | 
| 36 | 
            +
                  
         | 
| 37 | 
            +
                  response.class.should == Whuffiebank::GiveResponse
         | 
| 38 | 
            +
                  
         | 
| 39 | 
            +
                  response.result.should == 'success'
         | 
| 40 | 
            +
                  response.reason.should == nil
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
                
         | 
| 43 | 
            +
                should "return failure when trying to give whuffie " do
         | 
| 44 | 
            +
                  stub_post('/give/?', 'give_whuffie_error.json')
         | 
| 45 | 
            +
                  
         | 
| 46 | 
            +
                  response = Whuffiebank.give_whuffie('etagwerker','bad_password','rtopsy',12)
         | 
| 47 | 
            +
                  
         | 
| 48 | 
            +
                  response.class.should == Whuffiebank::GiveResponse
         | 
| 49 | 
            +
                  
         | 
| 50 | 
            +
                  response.result.should == 'failure'
         | 
| 51 | 
            +
                  
         | 
| 52 | 
            +
                  response.reason.should == INVALID_TWITTER_USERNAME
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
                
         | 
| 55 | 
            +
                should "return the whuffie information for a particular username " do
         | 
| 56 | 
            +
                  stub_get('/whuffie/?username=etagwerker','whuffie.json')
         | 
| 57 | 
            +
                  
         | 
| 58 | 
            +
                  response = Whuffiebank.whuffie('etagwerker')
         | 
| 59 | 
            +
                  
         | 
| 60 | 
            +
                  response.class.should == Whuffiebank::Whuffie
         | 
| 61 | 
            +
                  
         | 
| 62 | 
            +
                  response.result.should == 'success'
         | 
| 63 | 
            +
                  response.reason.should == nil
         | 
| 64 | 
            +
                  response.whuffie.should == 126
         | 
| 65 | 
            +
                  response.ranking.should == 287842
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
                
         | 
| 68 | 
            +
                should "return a failure because the whuffie account doesn't exist " do
         | 
| 69 | 
            +
                  stub_get('/whuffie/?username=account','whuffie_error.json')
         | 
| 70 | 
            +
                  
         | 
| 71 | 
            +
                  response = Whuffiebank.whuffie('account')
         | 
| 72 | 
            +
                  
         | 
| 73 | 
            +
                  response.result.should == 'failure'
         | 
| 74 | 
            +
                  response.reason.should == 'Whuffie Bank account not found'
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
              
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            end
         | 
    
        data/whuffiebank.gemspec
    ADDED
    
    | @@ -0,0 +1,83 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{whuffiebank}
         | 
| 8 | 
            +
              s.version = "0.1.0"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Ernesto Tagwerker"]
         | 
| 12 | 
            +
              s.date = %q{2010-01-25}
         | 
| 13 | 
            +
              s.description = %q{Ruby wrapper for the Whuffiebank API}
         | 
| 14 | 
            +
              s.email = %q{etagwerker@gmail.com}
         | 
| 15 | 
            +
              s.extra_rdoc_files = [
         | 
| 16 | 
            +
                "README",
         | 
| 17 | 
            +
                 "README.rdoc"
         | 
| 18 | 
            +
              ]
         | 
| 19 | 
            +
              s.files = [
         | 
| 20 | 
            +
                ".gitignore",
         | 
| 21 | 
            +
                 "History.txt",
         | 
| 22 | 
            +
                 "Manifest.txt",
         | 
| 23 | 
            +
                 "PostInstall.txt",
         | 
| 24 | 
            +
                 "README",
         | 
| 25 | 
            +
                 "README.rdoc",
         | 
| 26 | 
            +
                 "Rakefile",
         | 
| 27 | 
            +
                 "lib/whuffiebank.rb",
         | 
| 28 | 
            +
                 "lib/whuffiebank/balance.rb",
         | 
| 29 | 
            +
                 "lib/whuffiebank/client.rb",
         | 
| 30 | 
            +
                 "lib/whuffiebank/give_response.rb",
         | 
| 31 | 
            +
                 "lib/whuffiebank/whuffie.rb",
         | 
| 32 | 
            +
                 "script/console",
         | 
| 33 | 
            +
                 "script/destroy",
         | 
| 34 | 
            +
                 "script/generate",
         | 
| 35 | 
            +
                 "test/fixtures/balance.json",
         | 
| 36 | 
            +
                 "test/fixtures/balance_error.json",
         | 
| 37 | 
            +
                 "test/fixtures/give_whuffie.json",
         | 
| 38 | 
            +
                 "test/fixtures/give_whuffie_error.json",
         | 
| 39 | 
            +
                 "test/fixtures/whuffie.json",
         | 
| 40 | 
            +
                 "test/fixtures/whuffie_error.json",
         | 
| 41 | 
            +
                 "test/test_helper.rb",
         | 
| 42 | 
            +
                 "test/test_whuffiebank.rb",
         | 
| 43 | 
            +
                 "whuffiebank.gemspec"
         | 
| 44 | 
            +
              ]
         | 
| 45 | 
            +
              s.homepage = %q{http://github.com/etagwerker/whuffiebank}
         | 
| 46 | 
            +
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 47 | 
            +
              s.require_paths = ["lib"]
         | 
| 48 | 
            +
              s.rubygems_version = %q{1.3.5}
         | 
| 49 | 
            +
              s.summary = %q{Ruby wrapper for the Whuffiebank API}
         | 
| 50 | 
            +
              s.test_files = [
         | 
| 51 | 
            +
                "test/test_helper.rb",
         | 
| 52 | 
            +
                 "test/test_whuffiebank.rb"
         | 
| 53 | 
            +
              ]
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              if s.respond_to? :specification_version then
         | 
| 56 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 57 | 
            +
                s.specification_version = 3
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         | 
| 60 | 
            +
                  s.add_runtime_dependency(%q<hashie>, ["~> 0.1.3"])
         | 
| 61 | 
            +
                  s.add_runtime_dependency(%q<httparty>, ["~> 0.4.5"])
         | 
| 62 | 
            +
                  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 2.10.1"])
         | 
| 63 | 
            +
                  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
         | 
| 64 | 
            +
                  s.add_development_dependency(%q<mocha>, ["= 0.9.4"])
         | 
| 65 | 
            +
                  s.add_development_dependency(%q<fakeweb>, [">= 1.2.5"])
         | 
| 66 | 
            +
                else
         | 
| 67 | 
            +
                  s.add_dependency(%q<hashie>, ["~> 0.1.3"])
         | 
| 68 | 
            +
                  s.add_dependency(%q<httparty>, ["~> 0.4.5"])
         | 
| 69 | 
            +
                  s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.1"])
         | 
| 70 | 
            +
                  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
         | 
| 71 | 
            +
                  s.add_dependency(%q<mocha>, ["= 0.9.4"])
         | 
| 72 | 
            +
                  s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              else
         | 
| 75 | 
            +
                s.add_dependency(%q<hashie>, ["~> 0.1.3"])
         | 
| 76 | 
            +
                s.add_dependency(%q<httparty>, ["~> 0.4.5"])
         | 
| 77 | 
            +
                s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.1"])
         | 
| 78 | 
            +
                s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
         | 
| 79 | 
            +
                s.add_dependency(%q<mocha>, ["= 0.9.4"])
         | 
| 80 | 
            +
                s.add_dependency(%q<fakeweb>, [">= 1.2.5"])
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
            end
         | 
| 83 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,139 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: whuffiebank
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors: 
         | 
| 7 | 
            +
            - Ernesto Tagwerker
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            date: 2010-01-25 00:00:00 -05:00
         | 
| 13 | 
            +
            default_executable: 
         | 
| 14 | 
            +
            dependencies: 
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 16 | 
            +
              name: hashie
         | 
| 17 | 
            +
              type: :runtime
         | 
| 18 | 
            +
              version_requirement: 
         | 
| 19 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 20 | 
            +
                requirements: 
         | 
| 21 | 
            +
                - - ~>
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                    version: 0.1.3
         | 
| 24 | 
            +
                version: 
         | 
| 25 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 26 | 
            +
              name: httparty
         | 
| 27 | 
            +
              type: :runtime
         | 
| 28 | 
            +
              version_requirement: 
         | 
| 29 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 30 | 
            +
                requirements: 
         | 
| 31 | 
            +
                - - ~>
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 33 | 
            +
                    version: 0.4.5
         | 
| 34 | 
            +
                version: 
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              name: thoughtbot-shoulda
         | 
| 37 | 
            +
              type: :development
         | 
| 38 | 
            +
              version_requirement: 
         | 
| 39 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 40 | 
            +
                requirements: 
         | 
| 41 | 
            +
                - - ">="
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 43 | 
            +
                    version: 2.10.1
         | 
| 44 | 
            +
                version: 
         | 
| 45 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 46 | 
            +
              name: jnunemaker-matchy
         | 
| 47 | 
            +
              type: :development
         | 
| 48 | 
            +
              version_requirement: 
         | 
| 49 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 50 | 
            +
                requirements: 
         | 
| 51 | 
            +
                - - "="
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 53 | 
            +
                    version: 0.4.0
         | 
| 54 | 
            +
                version: 
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 56 | 
            +
              name: mocha
         | 
| 57 | 
            +
              type: :development
         | 
| 58 | 
            +
              version_requirement: 
         | 
| 59 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 60 | 
            +
                requirements: 
         | 
| 61 | 
            +
                - - "="
         | 
| 62 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 63 | 
            +
                    version: 0.9.4
         | 
| 64 | 
            +
                version: 
         | 
| 65 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 66 | 
            +
              name: fakeweb
         | 
| 67 | 
            +
              type: :development
         | 
| 68 | 
            +
              version_requirement: 
         | 
| 69 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 70 | 
            +
                requirements: 
         | 
| 71 | 
            +
                - - ">="
         | 
| 72 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 73 | 
            +
                    version: 1.2.5
         | 
| 74 | 
            +
                version: 
         | 
| 75 | 
            +
            description: Ruby wrapper for the Whuffiebank API
         | 
| 76 | 
            +
            email: etagwerker@gmail.com
         | 
| 77 | 
            +
            executables: []
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            extensions: []
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            extra_rdoc_files: 
         | 
| 82 | 
            +
            - README
         | 
| 83 | 
            +
            - README.rdoc
         | 
| 84 | 
            +
            files: 
         | 
| 85 | 
            +
            - .gitignore
         | 
| 86 | 
            +
            - History.txt
         | 
| 87 | 
            +
            - Manifest.txt
         | 
| 88 | 
            +
            - PostInstall.txt
         | 
| 89 | 
            +
            - README
         | 
| 90 | 
            +
            - README.rdoc
         | 
| 91 | 
            +
            - Rakefile
         | 
| 92 | 
            +
            - lib/whuffiebank.rb
         | 
| 93 | 
            +
            - lib/whuffiebank/balance.rb
         | 
| 94 | 
            +
            - lib/whuffiebank/client.rb
         | 
| 95 | 
            +
            - lib/whuffiebank/give_response.rb
         | 
| 96 | 
            +
            - lib/whuffiebank/whuffie.rb
         | 
| 97 | 
            +
            - script/console
         | 
| 98 | 
            +
            - script/destroy
         | 
| 99 | 
            +
            - script/generate
         | 
| 100 | 
            +
            - test/fixtures/balance.json
         | 
| 101 | 
            +
            - test/fixtures/balance_error.json
         | 
| 102 | 
            +
            - test/fixtures/give_whuffie.json
         | 
| 103 | 
            +
            - test/fixtures/give_whuffie_error.json
         | 
| 104 | 
            +
            - test/fixtures/whuffie.json
         | 
| 105 | 
            +
            - test/fixtures/whuffie_error.json
         | 
| 106 | 
            +
            - test/test_helper.rb
         | 
| 107 | 
            +
            - test/test_whuffiebank.rb
         | 
| 108 | 
            +
            - whuffiebank.gemspec
         | 
| 109 | 
            +
            has_rdoc: true
         | 
| 110 | 
            +
            homepage: http://github.com/etagwerker/whuffiebank
         | 
| 111 | 
            +
            licenses: []
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            post_install_message: 
         | 
| 114 | 
            +
            rdoc_options: 
         | 
| 115 | 
            +
            - --charset=UTF-8
         | 
| 116 | 
            +
            require_paths: 
         | 
| 117 | 
            +
            - lib
         | 
| 118 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 119 | 
            +
              requirements: 
         | 
| 120 | 
            +
              - - ">="
         | 
| 121 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 122 | 
            +
                  version: "0"
         | 
| 123 | 
            +
              version: 
         | 
| 124 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 125 | 
            +
              requirements: 
         | 
| 126 | 
            +
              - - ">="
         | 
| 127 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 128 | 
            +
                  version: "0"
         | 
| 129 | 
            +
              version: 
         | 
| 130 | 
            +
            requirements: []
         | 
| 131 | 
            +
             | 
| 132 | 
            +
            rubyforge_project: 
         | 
| 133 | 
            +
            rubygems_version: 1.3.5
         | 
| 134 | 
            +
            signing_key: 
         | 
| 135 | 
            +
            specification_version: 3
         | 
| 136 | 
            +
            summary: Ruby wrapper for the Whuffiebank API
         | 
| 137 | 
            +
            test_files: 
         | 
| 138 | 
            +
            - test/test_helper.rb
         | 
| 139 | 
            +
            - test/test_whuffiebank.rb
         |