rong_cloud 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 +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/lib/rong_cloud.rb +8 -0
- data/lib/rong_cloud/client.rb +66 -0
- data/lib/rong_cloud/errors.rb +25 -0
- data/lib/rong_cloud/version.rb +3 -0
- data/rong_cloud.gemspec +27 -0
- metadata +140 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: cf19d37bb18488c244dfe6ed507099bb0d262777
         | 
| 4 | 
            +
              data.tar.gz: 4fb64aaae7fd862add5fe3a6d0de107bf1e0dfac
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 2c588b521c375241a1aae6a1338ff1272affa9ac3908862f9b0d02bbbaaa3343b58f24f26d3732830858c87e860abc08d94012fc786f723f2c788cb6f634d7e9
         | 
| 7 | 
            +
              data.tar.gz: b7feb1ba6413688feed67e963bbb09addce24b888f29939f7fba0ba9d55a6ae1b3423186009886871eff43b272c9b8c081d79c6cd7dea33a80ee6ca904c4aafd
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            # RongCloud
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Unofficial RongCloud API wrapper.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'rong_cloud'
         | 
| 11 | 
            +
            ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            And then execute:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                $ bundle
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Or install it yourself as:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                $ gem install rong_cloud
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Usage
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ### Sample
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ```ruby
         | 
| 26 | 
            +
            client = RongCloud::Client.new(
         | 
| 27 | 
            +
              app_key: 'uwd1c0sxdlx2',
         | 
| 28 | 
            +
              app_secret: 'Y1W2MeFwwwRxa0'
         | 
| 29 | 
            +
            )
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            client.request(
         | 
| 32 | 
            +
              method: 'post',
         | 
| 33 | 
            +
              endpoint: '/message/private/publish.json',
         | 
| 34 | 
            +
              body: {
         | 
| 35 | 
            +
                content: {content: 'foo'}.to_json,
         | 
| 36 | 
            +
                'fromUserId' => '123',
         | 
| 37 | 
            +
                'toUserId' => '333',
         | 
| 38 | 
            +
                'objectName' => 'RC:TxtMsg'
         | 
| 39 | 
            +
              }
         | 
| 40 | 
            +
            )
         | 
| 41 | 
            +
            ```
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ## Development
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            ## Contributing
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rong_cloud.
         | 
| 52 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    
    
        data/bin/setup
    ADDED
    
    
    
        data/lib/rong_cloud.rb
    ADDED
    
    
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            require 'net/http'
         | 
| 2 | 
            +
            require 'json'
         | 
| 3 | 
            +
            require 'securerandom'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module RongCloud
         | 
| 6 | 
            +
              class Client
         | 
| 7 | 
            +
                DEFAULT_HOST = 'https://api.cn.rong.io'.freeze
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(host:DEFAULT_HOST, app_key:, app_secret:)
         | 
| 10 | 
            +
                  @host = host
         | 
| 11 | 
            +
                  @app_key = app_key
         | 
| 12 | 
            +
                  @app_secret = app_secret
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def request(method:, endpoint:'/', body:{}, headers:{})
         | 
| 16 | 
            +
                  uri = URI.join(@host, endpoint)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  method = Object.const_get("Net::HTTP::#{method.capitalize}")
         | 
| 19 | 
            +
                  request = method.new(uri)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  request.content_type = 'application/x-www-form-urlencoded'
         | 
| 22 | 
            +
                  request.set_form_data(body)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  request.initialize_http_header({
         | 
| 25 | 
            +
                    'App-Key' => @app_key,
         | 
| 26 | 
            +
                    'Nonce' => signature[:nonce],
         | 
| 27 | 
            +
                    'Timestamp' => signature[:timestamp].to_s,
         | 
| 28 | 
            +
                    'Signature' => signature[:signature]
         | 
| 29 | 
            +
                  })
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         | 
| 32 | 
            +
                  http.use_ssl = (uri.port == 443)
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  response = http.request(request)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
             | 
| 37 | 
            +
                  case response
         | 
| 38 | 
            +
                  when Net::HTTPSuccess then
         | 
| 39 | 
            +
                    return JSON.parse(response.body)
         | 
| 40 | 
            +
                  else
         | 
| 41 | 
            +
                    json = JSON.parse(response.body)
         | 
| 42 | 
            +
                    raise RongCloud::Errors::Standard.new(
         | 
| 43 | 
            +
                      error_code: json['code'],
         | 
| 44 | 
            +
                      error_message: json['errorMessage']
         | 
| 45 | 
            +
                    ), caller
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                private
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def signature
         | 
| 52 | 
            +
                  @signature ||= generate_signature
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def generate_signature
         | 
| 56 | 
            +
                  nonce = SecureRandom.hex
         | 
| 57 | 
            +
                  timestamp = Time.now.to_i
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  {
         | 
| 60 | 
            +
                    nonce: nonce,
         | 
| 61 | 
            +
                    timestamp: timestamp,
         | 
| 62 | 
            +
                    signature: Digest::SHA1.hexdigest("#{@app_secret}#{nonce}#{timestamp}")
         | 
| 63 | 
            +
                  }
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            module RongCloud
         | 
| 2 | 
            +
              class Errors
         | 
| 3 | 
            +
                Base = Class.new(StandardError)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                class Standard < Base
         | 
| 6 | 
            +
                  attr_reader :error_code, :error_message
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  DOC_URI = "http://www.rongcloud.cn/docs/server.html#API_方法返回值说明".freeze
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def initialize(error_code:, error_message:)
         | 
| 11 | 
            +
                    @error_code = error_code
         | 
| 12 | 
            +
                    @error_message = error_message
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def message
         | 
| 16 | 
            +
                    <<-EOS
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    Code: #{@error_code}
         | 
| 19 | 
            +
                    Message: #{@error_message}
         | 
| 20 | 
            +
                    Please read the doc: #{DOC_URI}
         | 
| 21 | 
            +
                    EOS
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
    
        data/rong_cloud.gemspec
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'rong_cloud/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "rong_cloud"
         | 
| 8 | 
            +
              spec.version       = RongCloud::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Jun Lin"]
         | 
| 10 | 
            +
              spec.email         = ["linjunpop@gmail.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{Unofficial RongCloud API wrapper.}
         | 
| 13 | 
            +
              spec.description   = %q{Unofficial RongCloud API wrapper.}
         | 
| 14 | 
            +
              spec.homepage      = "https://github.com/linjunpop/rong_cloud"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 17 | 
            +
              spec.bindir        = "exe"
         | 
| 18 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_development_dependency "bundler", "~> 1.10"
         | 
| 22 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 23 | 
            +
              spec.add_development_dependency "minitest"
         | 
| 24 | 
            +
              spec.add_development_dependency "pry"
         | 
| 25 | 
            +
              spec.add_development_dependency "pry-doc"
         | 
| 26 | 
            +
              spec.add_development_dependency "httplog"
         | 
| 27 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,140 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: rong_cloud
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Jun Lin
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-09-16 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.10'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.10'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: minitest
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: pry
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: pry-doc
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: httplog
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            description: Unofficial RongCloud API wrapper.
         | 
| 98 | 
            +
            email:
         | 
| 99 | 
            +
            - linjunpop@gmail.com
         | 
| 100 | 
            +
            executables: []
         | 
| 101 | 
            +
            extensions: []
         | 
| 102 | 
            +
            extra_rdoc_files: []
         | 
| 103 | 
            +
            files:
         | 
| 104 | 
            +
            - ".gitignore"
         | 
| 105 | 
            +
            - ".travis.yml"
         | 
| 106 | 
            +
            - Gemfile
         | 
| 107 | 
            +
            - README.md
         | 
| 108 | 
            +
            - Rakefile
         | 
| 109 | 
            +
            - bin/console
         | 
| 110 | 
            +
            - bin/setup
         | 
| 111 | 
            +
            - lib/rong_cloud.rb
         | 
| 112 | 
            +
            - lib/rong_cloud/client.rb
         | 
| 113 | 
            +
            - lib/rong_cloud/errors.rb
         | 
| 114 | 
            +
            - lib/rong_cloud/version.rb
         | 
| 115 | 
            +
            - rong_cloud.gemspec
         | 
| 116 | 
            +
            homepage: https://github.com/linjunpop/rong_cloud
         | 
| 117 | 
            +
            licenses: []
         | 
| 118 | 
            +
            metadata: {}
         | 
| 119 | 
            +
            post_install_message: 
         | 
| 120 | 
            +
            rdoc_options: []
         | 
| 121 | 
            +
            require_paths:
         | 
| 122 | 
            +
            - lib
         | 
| 123 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 124 | 
            +
              requirements:
         | 
| 125 | 
            +
              - - ">="
         | 
| 126 | 
            +
                - !ruby/object:Gem::Version
         | 
| 127 | 
            +
                  version: '0'
         | 
| 128 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
              requirements:
         | 
| 130 | 
            +
              - - ">="
         | 
| 131 | 
            +
                - !ruby/object:Gem::Version
         | 
| 132 | 
            +
                  version: '0'
         | 
| 133 | 
            +
            requirements: []
         | 
| 134 | 
            +
            rubyforge_project: 
         | 
| 135 | 
            +
            rubygems_version: 2.4.8
         | 
| 136 | 
            +
            signing_key: 
         | 
| 137 | 
            +
            specification_version: 4
         | 
| 138 | 
            +
            summary: Unofficial RongCloud API wrapper.
         | 
| 139 | 
            +
            test_files: []
         | 
| 140 | 
            +
            has_rdoc: 
         |