oauth2_china 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oauth2_china.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 cqpx
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,29 @@
1
+ # Oauth2China
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'oauth2_china'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install oauth2_china
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/examples/016.gif ADDED
Binary file
data/examples/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://ruby.taobao.org"
2
+
3
+ gem 'oauth2_china', path: "/Users/Pan/rails/oauth2_china/"
data/examples/img.jpeg ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ #coding: utf-8
2
+ require 'oauth2_china'
3
+
4
+ #sina = Oauth2China::Sina.new "2.00PvDQzBee3piCd9690cd4fcq5DwtB"
5
+ ##res = sina.statuses_update("ello wd")
6
+ ##p res
7
+ #res = sina.statuses_upload("come on gif", "./016.gif")
8
+ #p res
9
+
10
+ qq = Oauth2China::Tencent.new "88f6c1b65ff3dbd0ebdda3db123f791a", "7547D743583717EA820A834BE4B50255"
11
+ #qq = Oauth2China::Tencent.new "a92e335ad63b4d7dbf9ac9d299fe7817", "565f61c64aa43838af462b355022c562"
12
+ res = qq.statuses_update "hello world"
13
+ p res
@@ -0,0 +1,3 @@
1
+ module Oauth2China
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,115 @@
1
+ require "oauth2_china/version"
2
+ require "faraday"
3
+ require "hashie"
4
+ require "json"
5
+
6
+ module Oauth2China
7
+ class Base
8
+ end
9
+
10
+ class Sina < Oauth2China::Base
11
+ def initialize(access_token)
12
+ @access_token = access_token
13
+
14
+ @tmpl = Hashie::Mash.new({
15
+ access_token: access_token,
16
+ })
17
+
18
+ @conn = Faraday.new(:url => 'https://api.weibo.com') do |faraday|
19
+ faraday.request :multipart
20
+ faraday.request :url_encoded # form-encode POST params
21
+ faraday.response :logger # log requests to STDOUT
22
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
+ end
24
+ end
25
+
26
+ def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
27
+ params = @tmpl.clone
28
+ params.status = status
29
+ params.lat = latitude if latitude
30
+ params.long = longitutde if longitutde
31
+ params.annotation = annotation if annotation
32
+
33
+ res = @conn.post("/2/statuses/update.json", params).body
34
+ Hashie::Mash.new(JSON.parse res)
35
+ end
36
+
37
+ def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
38
+ params = @tmpl.clone
39
+ params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
40
+ params.status = status
41
+ params.lat = latitude if latitude
42
+ params.long = longitutde if longitutde
43
+ params.annotation = annotation if annotation
44
+
45
+ res = @conn.post("/2/statuses/upload.json", params).body
46
+ Hashie::Mash.new(JSON.parse res)
47
+ end
48
+
49
+ def friendships_create(uid)
50
+ params = @tmpl.clone
51
+
52
+ if uid.is_a? String
53
+ params.uid = uid
54
+ else
55
+ params.screen_name = uid
56
+ end
57
+
58
+ res = @conn.post("/2/friendships/create.json", params).body
59
+ Hashie::Mash.new(JSON.parse res)
60
+ end
61
+
62
+ def comments_create(id, comment, comment_ori = 0)
63
+ params = @tmpl.clone
64
+
65
+ params.id = id
66
+ params.comment = comment
67
+ params.comment_ori = comment_ori
68
+
69
+ res = @conn.post("/2/comments/create.json", params).body
70
+ Hashie::Mash.new(JSON.parse res)
71
+ end
72
+ end
73
+
74
+ class Tencent < Oauth2China::Base
75
+ def initialize(access_token, openid)
76
+ @conn = Faraday.new(:url => 'https://open.t.qq.com') do |faraday|
77
+ faraday.request :multipart
78
+ faraday.request :url_encoded # form-encode POST params
79
+ faraday.response :logger # log requests to STDOUT
80
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
81
+ end
82
+
83
+ @tmpl = Hashie::Mash.new({
84
+ oauth_consumer_key: 801183628,
85
+ access_token: access_token,
86
+ openid: openid,
87
+ clientip: '202.102.154.3',
88
+ oauth_version: '2.a',
89
+ format: "json"
90
+ })
91
+ end
92
+
93
+ def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
94
+ params = @tmpl.clone
95
+ params.content = status
96
+ params.jing = latitude if latitude
97
+ params.wei = longitutde if longitutde
98
+
99
+ res = @conn.post("/api/t/add", params.to_hash).body
100
+ Hashie::Mash.new(JSON.parse res)
101
+ end
102
+
103
+ def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
104
+ params = @tmpl.clone
105
+ params.content = status
106
+ params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
107
+ params.jing = latitude if latitude
108
+ params.wei = longitutde if longitutde
109
+
110
+ res = @conn.post("/api/t/add_pic", params.to_hash).body
111
+ Hashie::Mash.new(JSON.parse res)
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/oauth2_china/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["cqpx"]
6
+ gem.email = ["cqpanxu@gmail.com"]
7
+ gem.description = %q{weibo client for china.}
8
+ gem.summary = %q{weibo client for china. Currently support sina and qq apis.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "oauth2_china"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Oauth2China::VERSION
17
+
18
+ gem.add_dependency 'faraday'
19
+ gem.add_dependency 'hashie'
20
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth2_china
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cqpx
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70301666358620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70301666358620
25
+ - !ruby/object:Gem::Dependency
26
+ name: hashie
27
+ requirement: &70301666358100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70301666358100
36
+ description: weibo client for china.
37
+ email:
38
+ - cqpanxu@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - examples/016.gif
49
+ - examples/Gemfile
50
+ - examples/img.jpeg
51
+ - examples/tester.rb
52
+ - lib/oauth2_china.rb
53
+ - lib/oauth2_china/version.rb
54
+ - oauth2_china.gemspec
55
+ homepage: ''
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.16
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: weibo client for china. Currently support sina and qq apis.
79
+ test_files: []