bare 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/bare.gemspec +23 -0
- data/lib/bare/curl.rb +117 -0
- data/lib/bare/version.rb +3 -0
- data/lib/bare.rb +6 -0
- metadata +81 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: b5034f79c8acff546480b37c88b9a8e71079d59b
         | 
| 4 | 
            +
              data.tar.gz: bff1ddcb1b71cd3cbfbe14662c22d21c3641b153
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 277ccccb1de73f1a1663751e748ca0d9d0ae958a8e753947a81492da9ddab4af0f08807e79fecda8d2386f3695aabefd3e0a5cbcd2601a875f45970ac56ce241
         | 
| 7 | 
            +
              data.tar.gz: 7a0487184bbc590560dc81da9705c75b0ce82de9a055c4852a42083935212f394412b7dcb9ea356998cdda8893614d4bd0b0a3a787d6e80132aea8004a4f1bde
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Brandon Robins
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            # Bare
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Barebones requests for Ruby.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'bare'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install bare
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ### Functions
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            * `setCookie(url, parameters={}, https=false)` - Gets and sets a cookie, to the `cookie` attribute, from a given url using any given parameters
         | 
| 24 | 
            +
            * `get(url, parameters={}, https=false, cookie=self.cookie)` - GET request method
         | 
| 25 | 
            +
            * `post(url, parameters={}, https=false, cookie=self.cookie)` - POST request method
         | 
| 26 | 
            +
            * `put(url, parameters={}, https=false, cookie=self.cookie)` - PUT request method
         | 
| 27 | 
            +
            * `delete(url, parameters={}, https=false, cookie=self.cookie)` - DELETE request method
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ```ruby
         | 
| 30 | 
            +
            > require 'bare'
         | 
| 31 | 
            +
            > c = Bare::Curl
         | 
| 32 | 
            +
            > c.get('http://www.google.com')
         | 
| 33 | 
            +
            > c.body
         | 
| 34 | 
            +
            ```
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            ### Attributes
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            `body`, `code`, and `response` attributes are set after running `get`, `post`, `put`, or `delete` functions.
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            ```ruby
         | 
| 41 | 
            +
            > c.body
         | 
| 42 | 
            +
            => "<!doctype html>...</html>"
         | 
| 43 | 
            +
            > c.code
         | 
| 44 | 
            +
            => "200"
         | 
| 45 | 
            +
            > c.response
         | 
| 46 | 
            +
            => #<Net::HTTPOK 200 OK readbody=true>
         | 
| 47 | 
            +
            ```
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            ## Contributing
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            1. Fork it ( http://github.com/<my-github-username>/bare/fork )
         | 
| 52 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 53 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 54 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 55 | 
            +
            5. Create new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
    
        data/bare.gemspec
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'bare/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "bare"
         | 
| 8 | 
            +
              spec.version       = Bare::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Brandon Robins"]
         | 
| 10 | 
            +
              spec.email         = ["brandon@ourlabel.com"]
         | 
| 11 | 
            +
              spec.summary       = "Barebones RESTful requests for Ruby."
         | 
| 12 | 
            +
              spec.description   = "Barebones RESTful requests for Ruby."
         | 
| 13 | 
            +
              spec.homepage      = "http://www.github.com/eanlain/bare"
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_development_dependency "bundler", "~> 1.5"
         | 
| 22 | 
            +
              spec.add_development_dependency "rake"
         | 
| 23 | 
            +
            end
         | 
    
        data/lib/bare/curl.rb
    ADDED
    
    | @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            require 'net/http'
         | 
| 2 | 
            +
            require 'uri'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Bare
         | 
| 5 | 
            +
              class Curl
         | 
| 6 | 
            +
                class << self
         | 
| 7 | 
            +
                  attr_accessor :body
         | 
| 8 | 
            +
                  attr_accessor :code
         | 
| 9 | 
            +
                  attr_accessor :cookie
         | 
| 10 | 
            +
                  attr_accessor :response
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def setCookie(url, parameters={}, https=false)
         | 
| 13 | 
            +
                    uri, http = setupHttp(url, https)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    request = Net::HTTP::Post.new(uri.request_uri)
         | 
| 16 | 
            +
                    request.set_form_data(parameters)
         | 
| 17 | 
            +
                    response = http.request(request)
         | 
| 18 | 
            +
                    cookie = response.response['set-cookie']
         | 
| 19 | 
            +
                    self.cookie = cookie
         | 
| 20 | 
            +
                    return cookie
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def get(url, parameters={}, https=false, cookie=self.cookie)
         | 
| 24 | 
            +
                    reset_attr
         | 
| 25 | 
            +
                    full_url = url
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    if !parameters.empty?
         | 
| 28 | 
            +
                      full_url += "?"
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    parameters.each_with_index do |(k,v), index|
         | 
| 32 | 
            +
                      if index == 0
         | 
| 33 | 
            +
                        full_url += "#{k.to_s}=#{v.to_s}"
         | 
| 34 | 
            +
                      else
         | 
| 35 | 
            +
                        full_url += "&#{k.to_s}=#{v.to_s}"
         | 
| 36 | 
            +
                      end
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    uri, http = setupHttp(full_url, https)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    request = Net::HTTP::Get.new(uri.request_uri)
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    if !cookie.nil?
         | 
| 44 | 
            +
                      request['Cookie'] = cookie
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    set_attr(http.request(request))
         | 
| 48 | 
            +
                    return self.response
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def post(url, parameters={}, https=false, cookie=self.cookie)
         | 
| 52 | 
            +
                    reset_attr
         | 
| 53 | 
            +
                    uri, http = setupHttp(url, https)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    request = Net::HTTP::Post.new(uri.request_uri)
         | 
| 56 | 
            +
                    request.set_form_data(parameters)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    if !cookie.nil?
         | 
| 59 | 
            +
                      request['Cookie'] = cookie
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    set_attr(http.request(request))
         | 
| 63 | 
            +
                    return self.response
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  def put(url, parameters={}, https=false, cookie=self.cookie)
         | 
| 67 | 
            +
                    reset_attr
         | 
| 68 | 
            +
                    uri, http = setupHttp(url, https)
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    request = Net::HTTP::Put.new(uri.request_uri)
         | 
| 71 | 
            +
                    request.set_form_data(parameters)
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                    if !cookie.nil?
         | 
| 74 | 
            +
                      request['Cookie'] = cookie
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    set_attr(http.request(request))
         | 
| 78 | 
            +
                    return self.response
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  def delete(url, https=false, cookie=self.cookie)
         | 
| 82 | 
            +
                    reset_attr
         | 
| 83 | 
            +
                    uri, http = setupHttp(url, https)
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                    request = Net::HTTP::Delete.new(uri.request_uri)
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                    set_attr(http.request(request))
         | 
| 88 | 
            +
                    return self.response
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                protected
         | 
| 92 | 
            +
                  def reset_attr
         | 
| 93 | 
            +
                    self.body = nil
         | 
| 94 | 
            +
                    self.code = nil
         | 
| 95 | 
            +
                    self.response = nil
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                  def set_attr(response)
         | 
| 99 | 
            +
                    self.body = response.body
         | 
| 100 | 
            +
                    self.code = response.code
         | 
| 101 | 
            +
                    self.response = response
         | 
| 102 | 
            +
                  end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                  def setupHttp(url, https=false)
         | 
| 105 | 
            +
                    uri = URI.parse(url)
         | 
| 106 | 
            +
                    http = Net::HTTP.new(uri.host, uri.port)
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    if https == true
         | 
| 109 | 
            +
                      http.use_ssl = true
         | 
| 110 | 
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 111 | 
            +
                    end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                    return uri, http
         | 
| 114 | 
            +
                  end
         | 
| 115 | 
            +
                end    
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
            end
         | 
    
        data/lib/bare/version.rb
    ADDED
    
    
    
        data/lib/bare.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,81 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: bare
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Brandon Robins
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-02-03 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ~>
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.5'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ~>
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.5'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - '>='
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            description: Barebones RESTful requests for Ruby.
         | 
| 42 | 
            +
            email:
         | 
| 43 | 
            +
            - brandon@ourlabel.com
         | 
| 44 | 
            +
            executables: []
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files: []
         | 
| 47 | 
            +
            files:
         | 
| 48 | 
            +
            - .gitignore
         | 
| 49 | 
            +
            - Gemfile
         | 
| 50 | 
            +
            - LICENSE.txt
         | 
| 51 | 
            +
            - README.md
         | 
| 52 | 
            +
            - Rakefile
         | 
| 53 | 
            +
            - bare.gemspec
         | 
| 54 | 
            +
            - lib/bare.rb
         | 
| 55 | 
            +
            - lib/bare/curl.rb
         | 
| 56 | 
            +
            - lib/bare/version.rb
         | 
| 57 | 
            +
            homepage: http://www.github.com/eanlain/bare
         | 
| 58 | 
            +
            licenses:
         | 
| 59 | 
            +
            - MIT
         | 
| 60 | 
            +
            metadata: {}
         | 
| 61 | 
            +
            post_install_message: 
         | 
| 62 | 
            +
            rdoc_options: []
         | 
| 63 | 
            +
            require_paths:
         | 
| 64 | 
            +
            - lib
         | 
| 65 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 66 | 
            +
              requirements:
         | 
| 67 | 
            +
              - - '>='
         | 
| 68 | 
            +
                - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                  version: '0'
         | 
| 70 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
              requirements:
         | 
| 72 | 
            +
              - - '>='
         | 
| 73 | 
            +
                - !ruby/object:Gem::Version
         | 
| 74 | 
            +
                  version: '0'
         | 
| 75 | 
            +
            requirements: []
         | 
| 76 | 
            +
            rubyforge_project: 
         | 
| 77 | 
            +
            rubygems_version: 2.2.1
         | 
| 78 | 
            +
            signing_key: 
         | 
| 79 | 
            +
            specification_version: 4
         | 
| 80 | 
            +
            summary: Barebones RESTful requests for Ruby.
         | 
| 81 | 
            +
            test_files: []
         |