edm 0.0.5 → 0.0.6
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/lib/edm.rb +11 -8
- data/lib/edm/version.rb +1 -1
- metadata +3 -3
    
        data/lib/edm.rb
    CHANGED
    
    | @@ -1,30 +1,33 @@ | |
| 1 1 | 
             
            require "edm/version"
         | 
| 2 2 | 
             
            require "net/http"
         | 
| 3 | 
            -
             | 
| 4 3 | 
             
            module Edm
         | 
| 5 4 | 
             
              class EdmClient
         | 
| 6 | 
            -
                 | 
| 5 | 
            +
                DOMAIN = 'http://edm.demohour.com'
         | 
| 6 | 
            +
                def initialize(account, secret)
         | 
| 7 7 | 
             
                  @account = account
         | 
| 8 | 
            -
                  @ | 
| 8 | 
            +
                  @secret = secret
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            -
                attr_accessor :account, : | 
| 11 | 
            +
                attr_accessor :account, :secret
         | 
| 12 12 |  | 
| 13 | 
            -
                def  | 
| 13 | 
            +
                def request(url, http_method, options = {})
         | 
| 14 14 | 
             
                  sign = generate_sign(options)
         | 
| 15 | 
            -
                  options[ | 
| 16 | 
            -
                   | 
| 15 | 
            +
                  options[:sign] = sign
         | 
| 16 | 
            +
                  options[:account_key] = self.account
         | 
| 17 | 
            +
                  result = remote_request(http_method, url, options)
         | 
| 17 18 | 
             
                  return result.body
         | 
| 18 19 | 
             
                end
         | 
| 19 20 |  | 
| 20 21 | 
             
                def generate_sign(options = {})
         | 
| 21 22 | 
             
                  if options.length > 0
         | 
| 23 | 
            +
                    secret = self.secret
         | 
| 22 24 | 
             
                    str = options.to_a.sort.map { |c| "#{c[0]}=#{c[1]}" }.join('&')
         | 
| 23 | 
            -
                    sign = Digest::SHA1.hexdigest("#{str}#{ | 
| 25 | 
            +
                    sign = Digest::SHA1.hexdigest("#{str}#{secret}")
         | 
| 24 26 | 
             
                  end
         | 
| 25 27 | 
             
                end
         | 
| 26 28 |  | 
| 27 29 | 
             
                def remote_request(http_method, url, options = {})
         | 
| 30 | 
            +
                  url = DOMAIN + url
         | 
| 28 31 | 
             
                  case http_method
         | 
| 29 32 | 
             
                  when 'post'
         | 
| 30 33 | 
             
                    Net::HTTP.post_form(URI.parse(url), options)
         | 
    
        data/lib/edm/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: edm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -13,7 +13,7 @@ date: 2011-12-30 00:00:00.000000000Z | |
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: spec
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &70245374460660 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,7 +21,7 @@ dependencies: | |
| 21 21 | 
             
                    version: '0'
         | 
| 22 22 | 
             
              type: :development
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *70245374460660
         | 
| 25 25 | 
             
            description: demohour edm api
         | 
| 26 26 | 
             
            email:
         | 
| 27 27 | 
             
            - lijiping@demohour.com
         |