givey_ruby 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 +7 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +82 -0
- data/LICENSE +7 -0
- data/README.md +12 -0
- data/Rakefile +5 -0
- data/givey_ruby.gemspec +30 -0
- data/lib/givey_ruby/configuration.rb +39 -0
- data/lib/givey_ruby/controller.rb +65 -0
- data/lib/givey_ruby/model.rb +38 -0
- data/lib/givey_ruby/shared.rb +82 -0
- data/lib/givey_ruby/version.rb +3 -0
- data/lib/givey_ruby.rb +27 -0
- data/spec/factories.rb +3 -0
- data/spec/givey_ruby/controller_spec.rb +49 -0
- data/spec/givey_ruby/model_spec.rb +75 -0
- data/spec/givey_ruby_spec.rb +5 -0
- data/spec/log/development.log +9 -0
- data/spec/script/rails +1 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/givey_token_file +1 -0
- metadata +187 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            --color
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                givey_ruby (0.0.1.alpha)
         | 
| 5 | 
            +
                  httparty
         | 
| 6 | 
            +
                  oauth2
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            GEM
         | 
| 9 | 
            +
              remote: http://rubygems.org/
         | 
| 10 | 
            +
              specs:
         | 
| 11 | 
            +
                actionpack (3.2.5)
         | 
| 12 | 
            +
                  activemodel (= 3.2.5)
         | 
| 13 | 
            +
                  activesupport (= 3.2.5)
         | 
| 14 | 
            +
                  builder (~> 3.0.0)
         | 
| 15 | 
            +
                  erubis (~> 2.7.0)
         | 
| 16 | 
            +
                  journey (~> 1.0.1)
         | 
| 17 | 
            +
                  rack (~> 1.4.0)
         | 
| 18 | 
            +
                  rack-cache (~> 1.2)
         | 
| 19 | 
            +
                  rack-test (~> 0.6.1)
         | 
| 20 | 
            +
                  sprockets (~> 2.1.3)
         | 
| 21 | 
            +
                activemodel (3.2.5)
         | 
| 22 | 
            +
                  activesupport (= 3.2.5)
         | 
| 23 | 
            +
                  builder (~> 3.0.0)
         | 
| 24 | 
            +
                activesupport (3.2.5)
         | 
| 25 | 
            +
                  i18n (~> 0.6)
         | 
| 26 | 
            +
                  multi_json (~> 1.0)
         | 
| 27 | 
            +
                builder (3.0.4)
         | 
| 28 | 
            +
                diff-lcs (1.1.3)
         | 
| 29 | 
            +
                erubis (2.7.0)
         | 
| 30 | 
            +
                factory_girl (3.4.0)
         | 
| 31 | 
            +
                  activesupport (>= 3.0.0)
         | 
| 32 | 
            +
                faraday (0.8.1)
         | 
| 33 | 
            +
                  multipart-post (~> 1.1)
         | 
| 34 | 
            +
                hike (1.2.1)
         | 
| 35 | 
            +
                httparty (0.8.3)
         | 
| 36 | 
            +
                  multi_json (~> 1.0)
         | 
| 37 | 
            +
                  multi_xml
         | 
| 38 | 
            +
                httpauth (0.1)
         | 
| 39 | 
            +
                i18n (0.6.0)
         | 
| 40 | 
            +
                journey (1.0.4)
         | 
| 41 | 
            +
                jwt (0.1.5)
         | 
| 42 | 
            +
                  multi_json (>= 1.0)
         | 
| 43 | 
            +
                log_buddy (0.7.0)
         | 
| 44 | 
            +
                multi_json (1.3.6)
         | 
| 45 | 
            +
                multi_xml (0.5.1)
         | 
| 46 | 
            +
                multipart-post (1.1.5)
         | 
| 47 | 
            +
                oauth2 (0.8.0)
         | 
| 48 | 
            +
                  faraday (~> 0.8)
         | 
| 49 | 
            +
                  httpauth (~> 0.1)
         | 
| 50 | 
            +
                  jwt (~> 0.1.4)
         | 
| 51 | 
            +
                  multi_json (~> 1.0)
         | 
| 52 | 
            +
                  rack (~> 1.2)
         | 
| 53 | 
            +
                rack (1.4.1)
         | 
| 54 | 
            +
                rack-cache (1.2)
         | 
| 55 | 
            +
                  rack (>= 0.4)
         | 
| 56 | 
            +
                rack-test (0.6.2)
         | 
| 57 | 
            +
                  rack (>= 1.0)
         | 
| 58 | 
            +
                rake (0.9.2.2)
         | 
| 59 | 
            +
                rspec (2.10.0)
         | 
| 60 | 
            +
                  rspec-core (~> 2.10.0)
         | 
| 61 | 
            +
                  rspec-expectations (~> 2.10.0)
         | 
| 62 | 
            +
                  rspec-mocks (~> 2.10.0)
         | 
| 63 | 
            +
                rspec-core (2.10.1)
         | 
| 64 | 
            +
                rspec-expectations (2.10.0)
         | 
| 65 | 
            +
                  diff-lcs (~> 1.1.3)
         | 
| 66 | 
            +
                rspec-mocks (2.10.1)
         | 
| 67 | 
            +
                sprockets (2.1.3)
         | 
| 68 | 
            +
                  hike (~> 1.2)
         | 
| 69 | 
            +
                  rack (~> 1.0)
         | 
| 70 | 
            +
                  tilt (~> 1.1, != 1.3.0)
         | 
| 71 | 
            +
                tilt (1.3.3)
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            PLATFORMS
         | 
| 74 | 
            +
              ruby
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            DEPENDENCIES
         | 
| 77 | 
            +
              actionpack
         | 
| 78 | 
            +
              factory_girl
         | 
| 79 | 
            +
              givey_ruby!
         | 
| 80 | 
            +
              log_buddy
         | 
| 81 | 
            +
              rake
         | 
| 82 | 
            +
              rspec
         | 
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            Copyright (C) 2012 Givey Ltd
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    
    
        data/givey_ruby.gemspec
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "givey_ruby/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "givey_ruby"
         | 
| 7 | 
            +
              s.version     = GiveyRuby::VERSION
         | 
| 8 | 
            +
              s.authors     = ["nickflux"]
         | 
| 9 | 
            +
              s.email       = ["nick@givey.com"]
         | 
| 10 | 
            +
              s.homepage    = "http://github.com/giveydev/givey_ruby"
         | 
| 11 | 
            +
              s.summary     = %q{Ruby API for accessing Givey API}
         | 
| 12 | 
            +
              s.description = %q{General, controller and model methods for accessing Givey API from Ruby}
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              s.rubyforge_project = "givey_ruby"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 17 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 18 | 
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 19 | 
            +
              s.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              s.add_development_dependency "rake"
         | 
| 22 | 
            +
              s.add_development_dependency "rspec"
         | 
| 23 | 
            +
              s.add_development_dependency "factory_girl"
         | 
| 24 | 
            +
              s.add_development_dependency "log_buddy"
         | 
| 25 | 
            +
              s.add_development_dependency "actionpack"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              s.add_dependency 'httparty'
         | 
| 28 | 
            +
              s.add_dependency 'oauth2'
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            module GiveyRuby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              class Configuration
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def client(client_options = {})
         | 
| 6 | 
            +
                  @client ||= begin
         | 
| 7 | 
            +
                    # TODO: ensure consumer key and secret
         | 
| 8 | 
            +
                    @api_site   = client_options.include?(:api_site) ? client_options[:api_site] : "http://api.givey.com"
         | 
| 9 | 
            +
                    opts        = {:site => @api_site, :authorize_url => "/#{api_version}/oauth/authorize", :token_url => "/#{api_version}/oauth/token", :raise_errors => false}
         | 
| 10 | 
            +
                    @token_file = client_options.include?(:token_file) ? client_options[:token_file] : "../tmp/givey_token_file"
         | 
| 11 | 
            +
                    OAuth2::Client.new(client_options[:consumer_key], client_options[:consumer_secret], opts) do |builder|
         | 
| 12 | 
            +
                      # POST/PUT params encoders:
         | 
| 13 | 
            +
                      builder.request :multipart
         | 
| 14 | 
            +
                      builder.request :url_encoded
         | 
| 15 | 
            +
                      builder.adapter :net_http
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def api_version(version = "v1")
         | 
| 21 | 
            +
                  @api_version  ||= version
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def api_site
         | 
| 25 | 
            +
                  @api_site
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def token_file
         | 
| 29 | 
            +
                  @token_file
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def token_file=(file_path)
         | 
| 33 | 
            +
                  @token_file = file_path
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
             | 
| 39 | 
            +
            end
         | 
| @@ -0,0 +1,65 @@ | |
| 1 | 
            +
            module GiveyRuby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Controller
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                module InstanceMethods
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  def set_password_token(email, password)
         | 
| 8 | 
            +
                    begin
         | 
| 9 | 
            +
                      @access_token           = api_client.password.get_token(email, password)
         | 
| 10 | 
            +
                      session[:access_token]  = @access_token.token
         | 
| 11 | 
            +
                      me                      = JSON.parse(@access_token.get("/#{api_version}/me").body)
         | 
| 12 | 
            +
                      session[:user_id]       = me['id']
         | 
| 13 | 
            +
                      return true
         | 
| 14 | 
            +
                    rescue Exception => e
         | 
| 15 | 
            +
                      return false
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def login_token_user(token_string)
         | 
| 20 | 
            +
                    begin
         | 
| 21 | 
            +
                      @access_token           = OAuth2::AccessToken.new(api_client, token_string)
         | 
| 22 | 
            +
                      session[:access_token]  = token_string
         | 
| 23 | 
            +
                      me                      = JSON.parse(@access_token.get("/#{api_version}/me").body)
         | 
| 24 | 
            +
                      session[:user_id]       = me['id']
         | 
| 25 | 
            +
                      return true
         | 
| 26 | 
            +
                    rescue Exception => e
         | 
| 27 | 
            +
                      return false
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  def access_token
         | 
| 32 | 
            +
                    @access_token  ||= begin
         | 
| 33 | 
            +
                      if session[:access_token]
         | 
| 34 | 
            +
                        api_token               = OAuth2::AccessToken.new(api_client, session[:access_token])
         | 
| 35 | 
            +
                      elsif givey_token = token_from_file
         | 
| 36 | 
            +
                        api_token = OAuth2::AccessToken.new(api_client, givey_token)
         | 
| 37 | 
            +
                      else
         | 
| 38 | 
            +
                        api_token               = api_client.client_credentials.get_token
         | 
| 39 | 
            +
                        session[:access_token]  = api_token.token
         | 
| 40 | 
            +
                        token_to_file(api_token.token)
         | 
| 41 | 
            +
                      end
         | 
| 42 | 
            +
                      api_token
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  # CLIENT CREDENTIALS ACCESS
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def token_sign_out
         | 
| 49 | 
            +
                    access_token.get("/#{api_version}/oauth/revoke")
         | 
| 50 | 
            +
                    session[:access_token]  = nil
         | 
| 51 | 
            +
                    session[:user_id]       = nil
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def self.included(receiver)
         | 
| 57 | 
            +
                  receiver.extend         GiveyRuby::Shared::ClassMethods
         | 
| 58 | 
            +
                  receiver.send :include, GiveyRuby::Shared::InstanceMethods
         | 
| 59 | 
            +
                  receiver.send :include, InstanceMethods
         | 
| 60 | 
            +
                  receiver.send :setup_givey_sdk
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            module GiveyRuby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Model
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                module ClassMethods
         | 
| 6 | 
            +
                  def setup_givey_sdk(options = {})
         | 
| 7 | 
            +
                    #options             = default_model_options.merge(options)
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                module InstanceMethods
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def access_token
         | 
| 14 | 
            +
                    @access_token  ||= begin
         | 
| 15 | 
            +
                      if self.respond_to?(:givey_token) && self.givey_token
         | 
| 16 | 
            +
                        api_token = OAuth2::AccessToken.new(api_client, self.givey_token)
         | 
| 17 | 
            +
                      elsif givey_token = token_from_file
         | 
| 18 | 
            +
                        api_token = OAuth2::AccessToken.new(api_client, givey_token)
         | 
| 19 | 
            +
                      else
         | 
| 20 | 
            +
                        api_token = api_client.client_credentials.get_token
         | 
| 21 | 
            +
                        token_to_file(api_token.token)
         | 
| 22 | 
            +
                      end
         | 
| 23 | 
            +
                      api_token
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def self.included(receiver)
         | 
| 30 | 
            +
                  receiver.extend         GiveyRuby::Shared::ClassMethods
         | 
| 31 | 
            +
                  receiver.send :include, GiveyRuby::Shared::InstanceMethods
         | 
| 32 | 
            +
                  receiver.send :include, InstanceMethods
         | 
| 33 | 
            +
                  receiver.send :setup_givey_sdk
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            end
         | 
| @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            module GiveyRuby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Shared
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                module ClassMethods
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  def setup_givey_sdk(options = {})
         | 
| 8 | 
            +
                    #options             = default_model_options.merge(options)
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                module InstanceMethods
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def api_client
         | 
| 16 | 
            +
                    @api_client ||= GiveyRuby.configuration.client
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def api_version
         | 
| 20 | 
            +
                    @api_version ||= GiveyRuby.configuration.api_version
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def token_from_file
         | 
| 24 | 
            +
                    if File.exists?(GiveyRuby.configuration.token_file)
         | 
| 25 | 
            +
                      File.read(GiveyRuby.configuration.token_file).gsub(/\n/, '')
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def token_to_file(token_string)
         | 
| 30 | 
            +
                    File.open(GiveyRuby.configuration.token_file, 'w'){|f| f.write(token_string) }
         | 
| 31 | 
            +
                    token_string
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  # PASSWORD
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  # CLIENT CREDENTIALS ACCESS
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def get_token_response(url)
         | 
| 39 | 
            +
                    JSON.parse(access_token.get("/#{api_version}#{url}").body)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def post_token_response(url, body, headers = {})
         | 
| 43 | 
            +
                    body      = find_files_for_conversion(body)
         | 
| 44 | 
            +
                    response  = access_token.post("/#{api_version}#{url}", {body: body, headers: headers})
         | 
| 45 | 
            +
                    JSON.parse(response.body)
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def put_token_response(url, body, headers = {})
         | 
| 49 | 
            +
                    body      = find_files_for_conversion(body)
         | 
| 50 | 
            +
                    response  = access_token.put("/#{api_version}#{url}", {body: body, headers: headers})
         | 
| 51 | 
            +
                    JSON.parse(response.body)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def find_files_for_conversion(body, parents = [])
         | 
| 55 | 
            +
                    @body ||= body
         | 
| 56 | 
            +
                    body.each do |param, value|
         | 
| 57 | 
            +
                      if value.kind_of?(Hash)
         | 
| 58 | 
            +
                        parents.push(param)
         | 
| 59 | 
            +
                        find_files_for_conversion(value, parents)
         | 
| 60 | 
            +
                      else
         | 
| 61 | 
            +
                        if upload_io = convert_files_for_upload(value)
         | 
| 62 | 
            +
                          eval("@body[:#{parents.map(&:to_sym).join("][:")}][:#{param}] = upload_io")
         | 
| 63 | 
            +
                        end
         | 
| 64 | 
            +
                      end
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  # replace avatar object (ActionDispatch::Http::UploadedFile) with UploadIO object
         | 
| 69 | 
            +
                  def convert_files_for_upload(value)
         | 
| 70 | 
            +
                    if value.kind_of?(ActionDispatch::Http::UploadedFile)
         | 
| 71 | 
            +
                      upload_io = UploadIO.new(value.tempfile.path, value.content_type, value.original_filename)
         | 
| 72 | 
            +
                      return upload_io
         | 
| 73 | 
            +
                    else
         | 
| 74 | 
            +
                      false
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            end
         | 
    
        data/lib/givey_ruby.rb
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'net/http/post/multipart'
         | 
| 2 | 
            +
            require 'oauth2'
         | 
| 3 | 
            +
            require 'httparty'
         | 
| 4 | 
            +
            require 'givey_ruby/version'
         | 
| 5 | 
            +
            require 'givey_ruby/configuration'
         | 
| 6 | 
            +
            require 'givey_ruby/shared'
         | 
| 7 | 
            +
            require 'givey_ruby/controller'
         | 
| 8 | 
            +
            require 'givey_ruby/model'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module GiveyRuby
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def self.configuration
         | 
| 13 | 
            +
                @configuration ||= GiveyRuby::Configuration.new
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              # Yields the global configuration to a block.
         | 
| 17 | 
            +
              # @yield [Configuration] global configuration
         | 
| 18 | 
            +
              #
         | 
| 19 | 
            +
              # @example
         | 
| 20 | 
            +
              #     GiveySdk.configure do |config|
         | 
| 21 | 
            +
              #       config.client 'documentation'
         | 
| 22 | 
            +
              #     end
         | 
| 23 | 
            +
              def self.configure
         | 
| 24 | 
            +
                yield configuration if block_given?
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            end
         | 
    
        data/spec/factories.rb
    ADDED
    
    
| @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require 'action_controller'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe GiveyRuby::Controller do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              class CharityController
         | 
| 7 | 
            +
                include GiveyRuby::Controller
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              GiveyRuby.configure do |config|
         | 
| 11 | 
            +
                config.client({token_file: "#{SPEC_ROOT}/tmp/givey_token_file"})
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              let(:charity_controller) { CharityController.new }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
             | 
| 17 | 
            +
              describe "access_token" do
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                let(:api_token) { stub('api_token', token: 'udhs7gf7ssg') }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                it "should get new token and update session if it doesn't exist" do
         | 
| 22 | 
            +
                  charity_controller.stub(:session).and_return({})
         | 
| 23 | 
            +
                  charity_controller.stub_chain(:api_client, :client_credentials, :get_token).and_return(api_token)
         | 
| 24 | 
            +
                  charity_controller.access_token.should == api_token
         | 
| 25 | 
            +
                  charity_controller.session[:access_token].should == 'udhs7gf7ssg'
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                it "should get token from existing session" do
         | 
| 29 | 
            +
                  charity_controller.should_receive(:session).twice.and_return({access_token: '8h7g6f5fjshd'})
         | 
| 30 | 
            +
                  OAuth2::AccessToken.should_receive(:new).and_return(api_token)
         | 
| 31 | 
            +
                  charity_controller.access_token.should == api_token
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              describe "get_token_response" do
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                let(:api_token) { stub('api_token', token: 'udhs7gf7ssg') }
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it "returns hash for requested URL" do
         | 
| 41 | 
            +
                  charity_controller.should_receive(:session).twice.and_return({access_token: '8h7g6f5fjshd'})
         | 
| 42 | 
            +
                  OAuth2::AccessToken.should_receive(:new).and_return(api_token)
         | 
| 43 | 
            +
                  charity_controller.access_token.stub_chain(:get, :body).and_return({this: 'that'}.to_json)
         | 
| 44 | 
            +
                  charity_controller.get_token_response("/this").should == {"this" => 'that'}
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            end
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe GiveyRuby::Model do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class Charity
         | 
| 6 | 
            +
                include GiveyRuby::Model
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              GiveyRuby.configure do |config|
         | 
| 10 | 
            +
                config.client({token_file: "#{SPEC_ROOT}/tmp/givey_token_file"})
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              let(:charity) { Charity.new }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              describe "token_from_file" do
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                after(:each) do
         | 
| 18 | 
            +
                  GiveyRuby.configuration.token_file = "#{SPEC_ROOT}/tmp/givey_token_file"
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                it "Charity object should return token string from file" do
         | 
| 22 | 
            +
                  GiveyRuby.configuration.token_file = "#{SPEC_ROOT}/support/givey_token_file"
         | 
| 23 | 
            +
                  charity.token_from_file.should == '1234rtyfh'
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                it "Charity object should return false if file doesn't exist" do
         | 
| 27 | 
            +
                  GiveyRuby.configuration.token_file = "#{SPEC_ROOT}/support/no_givey_token_file"
         | 
| 28 | 
            +
                  charity.token_from_file.should be_false
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              describe "token_to_file" do
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "Charity object should create and populate token string to file" do
         | 
| 36 | 
            +
                  File.exists?(GiveyRuby.configuration.token_file).should be_false
         | 
| 37 | 
            +
                  charity.token_to_file('8h7g6f5fjshd')
         | 
| 38 | 
            +
                  File.exists?(GiveyRuby.configuration.token_file).should be_true
         | 
| 39 | 
            +
                  charity.token_from_file.should == '8h7g6f5fjshd'
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              describe "access_token" do
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                let(:api_token) { stub('api_token', token: 'udhs7gf7ssg') }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it "should get new token and create token_file if it doesn't exist" do
         | 
| 49 | 
            +
                  charity.stub_chain(:api_client, :client_credentials, :get_token).and_return(api_token)
         | 
| 50 | 
            +
                  charity.access_token.should == api_token
         | 
| 51 | 
            +
                  File.read(GiveyRuby.configuration.token_file).gsub(/\n/, '').should == 'udhs7gf7ssg'
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                it "should get token from existing token_file" do
         | 
| 55 | 
            +
                  File.open(GiveyRuby.configuration.token_file, 'w'){|f| f.write('8h7g6f5fjshd') }
         | 
| 56 | 
            +
                  OAuth2::AccessToken.should_receive(:new).and_return(api_token)
         | 
| 57 | 
            +
                  charity.access_token.should == api_token
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              describe "get_token_response" do
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                let(:api_token) { stub('api_token', token: 'udhs7gf7ssg') }
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                it "returns hash for requested URL" do
         | 
| 67 | 
            +
                  File.open(GiveyRuby.configuration.token_file, 'w'){|f| f.write('8h7g6f5fjshd') }
         | 
| 68 | 
            +
                  OAuth2::AccessToken.should_receive(:new).and_return(api_token)
         | 
| 69 | 
            +
                  charity.access_token.stub_chain(:get, :body).and_return({this: 'that'}.to_json)
         | 
| 70 | 
            +
                  charity.get_token_response("/this").should == {"this" => 'that'}
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            end
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            Processing by CharitiesController#index as HTML
         | 
| 2 | 
            +
              Rendered text template (0.0ms)
         | 
| 3 | 
            +
            Completed 200 OK in 36ms (Views: 36.1ms)
         | 
| 4 | 
            +
            Processing by CharitiesController#index as HTML
         | 
| 5 | 
            +
              Rendered text template (0.0ms)
         | 
| 6 | 
            +
            Completed 200 OK in 50ms (Views: 50.2ms)
         | 
| 7 | 
            +
            Processing by CharitiesController#index as HTML
         | 
| 8 | 
            +
              Rendered text template (0.0ms)
         | 
| 9 | 
            +
            Completed 200 OK in 33ms (Views: 33.2ms)
         | 
    
        data/spec/script/rails
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
             | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            SPEC_ROOT = File.expand_path('..', __FILE__)
         | 
| 2 | 
            +
            require 'givey_ruby'
         | 
| 3 | 
            +
            require 'factory_girl'
         | 
| 4 | 
            +
            require 'log_buddy'
         | 
| 5 | 
            +
            require 'json'
         | 
| 6 | 
            +
            require "#{SPEC_ROOT}/factories.rb"
         | 
| 7 | 
            +
            Dir["#{SPEC_ROOT}/support/**/*.rb"].each { |file| require file }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # autoload models
         | 
| 10 | 
            +
            #Dir["spec/models/*.rb"].each do |file|
         | 
| 11 | 
            +
            #  autoload File.basename(file, ".rb").titleize.to_sym, "models/#{File.basename(file, ".#rb")}"
         | 
| 12 | 
            +
            #end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
             | 
| 15 | 
            +
            RSpec.configure do |config|
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              require 'rspec/expectations'
         | 
| 18 | 
            +
              config.include RSpec::Matchers
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              config.include FactoryGirl::Syntax::Methods
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              # only run specs tagged with focus id any are tagged
         | 
| 23 | 
            +
              config.treat_symbols_as_metadata_keys_with_true_values = true
         | 
| 24 | 
            +
              config.filter_run :focus => true
         | 
| 25 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              config.before(:each) do
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              config.after(:each) do
         | 
| 31 | 
            +
                Dir.glob("#{SPEC_ROOT}/tmp/*").each {|f| File.delete(f) }
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              config.after(:all) do
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            end
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            1234rtyfh
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,187 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: givey_ruby
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - nickflux
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2013-01-10 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: rake
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ! '>='
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: '0'
         | 
| 22 | 
            +
              type: :development
         | 
| 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 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 31 | 
            +
              name: rspec
         | 
| 32 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            +
                none: false
         | 
| 34 | 
            +
                requirements:
         | 
| 35 | 
            +
                - - ! '>='
         | 
| 36 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                    version: '0'
         | 
| 38 | 
            +
              type: :development
         | 
| 39 | 
            +
              prerelease: false
         | 
| 40 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
                none: false
         | 
| 42 | 
            +
                requirements:
         | 
| 43 | 
            +
                - - ! '>='
         | 
| 44 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                    version: '0'
         | 
| 46 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 47 | 
            +
              name: factory_girl
         | 
| 48 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
                none: false
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - ! '>='
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '0'
         | 
| 54 | 
            +
              type: :development
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                none: false
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ! '>='
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 63 | 
            +
              name: log_buddy
         | 
| 64 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                none: false
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - ! '>='
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: '0'
         | 
| 70 | 
            +
              type: :development
         | 
| 71 | 
            +
              prerelease: false
         | 
| 72 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                none: false
         | 
| 74 | 
            +
                requirements:
         | 
| 75 | 
            +
                - - ! '>='
         | 
| 76 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            +
                    version: '0'
         | 
| 78 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 79 | 
            +
              name: actionpack
         | 
| 80 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 81 | 
            +
                none: false
         | 
| 82 | 
            +
                requirements:
         | 
| 83 | 
            +
                - - ! '>='
         | 
| 84 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 85 | 
            +
                    version: '0'
         | 
| 86 | 
            +
              type: :development
         | 
| 87 | 
            +
              prerelease: false
         | 
| 88 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 89 | 
            +
                none: false
         | 
| 90 | 
            +
                requirements:
         | 
| 91 | 
            +
                - - ! '>='
         | 
| 92 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 93 | 
            +
                    version: '0'
         | 
| 94 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 95 | 
            +
              name: httparty
         | 
| 96 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
                none: false
         | 
| 98 | 
            +
                requirements:
         | 
| 99 | 
            +
                - - ! '>='
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                    version: '0'
         | 
| 102 | 
            +
              type: :runtime
         | 
| 103 | 
            +
              prerelease: false
         | 
| 104 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 105 | 
            +
                none: false
         | 
| 106 | 
            +
                requirements:
         | 
| 107 | 
            +
                - - ! '>='
         | 
| 108 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 109 | 
            +
                    version: '0'
         | 
| 110 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 111 | 
            +
              name: oauth2
         | 
| 112 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 113 | 
            +
                none: false
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ! '>='
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                none: false
         | 
| 122 | 
            +
                requirements:
         | 
| 123 | 
            +
                - - ! '>='
         | 
| 124 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 125 | 
            +
                    version: '0'
         | 
| 126 | 
            +
            description: General, controller and model methods for accessing Givey API from Ruby
         | 
| 127 | 
            +
            email:
         | 
| 128 | 
            +
            - nick@givey.com
         | 
| 129 | 
            +
            executables: []
         | 
| 130 | 
            +
            extensions: []
         | 
| 131 | 
            +
            extra_rdoc_files: []
         | 
| 132 | 
            +
            files:
         | 
| 133 | 
            +
            - .gitignore
         | 
| 134 | 
            +
            - .rspec
         | 
| 135 | 
            +
            - Gemfile
         | 
| 136 | 
            +
            - Gemfile.lock
         | 
| 137 | 
            +
            - LICENSE
         | 
| 138 | 
            +
            - README.md
         | 
| 139 | 
            +
            - Rakefile
         | 
| 140 | 
            +
            - givey_ruby.gemspec
         | 
| 141 | 
            +
            - lib/givey_ruby.rb
         | 
| 142 | 
            +
            - lib/givey_ruby/configuration.rb
         | 
| 143 | 
            +
            - lib/givey_ruby/controller.rb
         | 
| 144 | 
            +
            - lib/givey_ruby/model.rb
         | 
| 145 | 
            +
            - lib/givey_ruby/shared.rb
         | 
| 146 | 
            +
            - lib/givey_ruby/version.rb
         | 
| 147 | 
            +
            - spec/factories.rb
         | 
| 148 | 
            +
            - spec/givey_ruby/controller_spec.rb
         | 
| 149 | 
            +
            - spec/givey_ruby/model_spec.rb
         | 
| 150 | 
            +
            - spec/givey_ruby_spec.rb
         | 
| 151 | 
            +
            - spec/log/development.log
         | 
| 152 | 
            +
            - spec/script/rails
         | 
| 153 | 
            +
            - spec/spec_helper.rb
         | 
| 154 | 
            +
            - spec/support/givey_token_file
         | 
| 155 | 
            +
            homepage: http://github.com/giveydev/givey_ruby
         | 
| 156 | 
            +
            licenses: []
         | 
| 157 | 
            +
            post_install_message: 
         | 
| 158 | 
            +
            rdoc_options: []
         | 
| 159 | 
            +
            require_paths:
         | 
| 160 | 
            +
            - lib
         | 
| 161 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 162 | 
            +
              none: false
         | 
| 163 | 
            +
              requirements:
         | 
| 164 | 
            +
              - - ! '>='
         | 
| 165 | 
            +
                - !ruby/object:Gem::Version
         | 
| 166 | 
            +
                  version: '0'
         | 
| 167 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 168 | 
            +
              none: false
         | 
| 169 | 
            +
              requirements:
         | 
| 170 | 
            +
              - - ! '>='
         | 
| 171 | 
            +
                - !ruby/object:Gem::Version
         | 
| 172 | 
            +
                  version: '0'
         | 
| 173 | 
            +
            requirements: []
         | 
| 174 | 
            +
            rubyforge_project: givey_ruby
         | 
| 175 | 
            +
            rubygems_version: 1.8.24
         | 
| 176 | 
            +
            signing_key: 
         | 
| 177 | 
            +
            specification_version: 3
         | 
| 178 | 
            +
            summary: Ruby API for accessing Givey API
         | 
| 179 | 
            +
            test_files:
         | 
| 180 | 
            +
            - spec/factories.rb
         | 
| 181 | 
            +
            - spec/givey_ruby/controller_spec.rb
         | 
| 182 | 
            +
            - spec/givey_ruby/model_spec.rb
         | 
| 183 | 
            +
            - spec/givey_ruby_spec.rb
         | 
| 184 | 
            +
            - spec/log/development.log
         | 
| 185 | 
            +
            - spec/script/rails
         | 
| 186 | 
            +
            - spec/spec_helper.rb
         | 
| 187 | 
            +
            - spec/support/givey_token_file
         |