gdouban 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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'httparty'
4
+ gem 'rest-client'
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ httparty (0.8.1)
5
+ multi_json
6
+ multi_xml
7
+ mime-types (1.19)
8
+ multi_json (1.0.4)
9
+ multi_xml (0.4.1)
10
+ rest-client (1.6.7)
11
+ mime-types (>= 1.16)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ httparty
18
+ rest-client
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Scott Ballantyne
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+
2
+ A third party, non-official douban API gem created by goshan. Inspired by goshan's sina API gem.
3
+
4
+ To install the gem simply enter:
5
+
6
+ gem install gdouban
7
+
8
+ This is a minimalistic API implementation, where all function calls goes through a single method. For example to publish a feed item one might do the following:
9
+
10
+ param = {:name => "blahblah"}
11
+ douban = Douban::Base.new(token)
12
+ douban.call_method("get", "user/param[:name]", param)
13
+
14
+ the token should be got by yourself
15
+
16
+ This gem was made in the process of creating 一见关注 [http://easyfollow.com], please take a moment and go and check out that project for example usage.
17
+
18
+ == Sites using the douban gem
19
+ easyFollow http://easyfollow.com
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/gdouban.gemspec ADDED
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gdouban}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["goshan"]
12
+ s.date = %q{2012-10-22}
13
+ s.description = %q{this gem is a simple one for call for douban api}
14
+ s.email = %q{goshan.hanqiu@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "VERSION",
25
+ "lib/gdouban.rb",
26
+ "lib/gdouban/base.rb",
27
+ "lib/gdouban/config.rb",
28
+ "gdouban.gemspec",
29
+ "gdouban.yml.example"
30
+ ]
31
+ s.homepage = %q{https://github.com/goshan/DoubanSDKGem}
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{a gem to help api integration for douban (www.douban.com)}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
42
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
43
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.6.7"])
44
+ else
45
+ s.add_dependency(%q<httparty>, [">= 0"])
46
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
47
+ s.add_dependency(%q<rest-client>, [">= 1.6.7"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<httparty>, [">= 0"])
51
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
52
+ s.add_dependency(%q<rest-client>, [">= 1.6.7"])
53
+ end
54
+ end
55
+
@@ -0,0 +1,9 @@
1
+ development:
2
+ app_key: app_key
3
+ secret_key: secret_key
4
+ test``:
5
+ app_key: app_key
6
+ secret_key: secret_key
7
+ production:
8
+ app_key: app_key
9
+ secret_key: secret_key
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'uri'
3
+ require 'multi_json'
4
+ require 'net/http'
5
+ require 'digest'
6
+ require 'rest_client'
7
+
8
+ module GDouban
9
+ class Base
10
+ attr_accessor :params
11
+
12
+ def initialize(access_token)
13
+ @params = {}
14
+ @params["apikey"] = Config.app_key
15
+ @params["Authorization"] = "Bearer #{access_token}"
16
+ end
17
+
18
+ def call_method(request_type, method="user/~me", params = {})
19
+ url = URI.parse("https://api.douban.com/v2/#{method}")
20
+ http = Net::HTTP.new(url.host, url.port)
21
+ http.use_ssl = true if url.scheme == 'https'
22
+ if request_type == "get"
23
+ request = Net::HTTP::Get.new("#{url.path}?#{params_to_string(params)}", @params)
24
+ elsif request_type == "post"
25
+ request = Net::HTTP::Post.new("#{url.path}", @params)
26
+ request.set_form_data(params)
27
+ end
28
+ puts http.request(request).header.inspect
29
+ MultiJson.decode(http.request(request).body)
30
+ end
31
+
32
+
33
+ private
34
+ def params_to_string(params)
35
+ params.map{|key, value| "#{key}=#{value}"}.join("&")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ module GDouban
2
+ module Config
3
+
4
+ def self.app_key=(val)
5
+ @@app_key = val
6
+ end
7
+
8
+ def self.app_key
9
+ @@app_key
10
+ end
11
+
12
+ def self.secret_key=(val)
13
+ @@secret_key = val
14
+ end
15
+
16
+ def self.secret_key
17
+ @@secret_key
18
+ end
19
+
20
+ end
21
+ end
data/lib/gdouban.rb ADDED
@@ -0,0 +1,13 @@
1
+ # code is an adaptation of the twitter gem by John Nunemaker
2
+ # http://github.com/jnunemaker/twitter
3
+ # Copyright (c) 2009 John Nunemaker
4
+ #
5
+ # made to work with china's facebook, 人人网
6
+
7
+ require 'gdouban/config'
8
+ require 'gdouban/base'
9
+ if File.exists?('config/gdouban.yml')
10
+ weibo_oauth = YAML.load_file('config/gdouban.yml')[Rails.env || env || 'development']
11
+ Sina::Config.app_key = weibo_oauth["app_key"]
12
+ Sina::Config.secret_key = weibo_oauth["secret_key"]
13
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gdouban
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - goshan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !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: !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: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.6.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.7
62
+ description: this gem is a simple one for call for douban api
63
+ email: goshan.hanqiu@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - LICENSE
68
+ - README.rdoc
69
+ files:
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE
73
+ - README.rdoc
74
+ - VERSION
75
+ - lib/gdouban.rb
76
+ - lib/gdouban/base.rb
77
+ - lib/gdouban/config.rb
78
+ - gdouban.gemspec
79
+ - gdouban.yml.example
80
+ homepage: https://github.com/goshan/DoubanSDKGem
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.24
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: a gem to help api integration for douban (www.douban.com)
104
+ test_files: []