frankel_weibo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/frankel_weibo.rb +78 -1
- data/lib/frankel_weibo/version.rb +1 -1
- metadata +1 -1
data/lib/frankel_weibo.rb
CHANGED
@@ -1,5 +1,82 @@
|
|
1
1
|
require "frankel_weibo/version"
|
2
2
|
|
3
|
+
# module FrankelWeibo
|
4
|
+
# # Your code goes here...
|
5
|
+
# end
|
6
|
+
|
7
|
+
|
8
|
+
# code is an adaptation of the twitter gem by John Nunemaker
|
9
|
+
# http://github.com/jnunemaker/twitter
|
10
|
+
# Copyright (c) 2009 John Nunemaker
|
11
|
+
#
|
12
|
+
# made to work with china's leading twitter service, 新浪微博
|
13
|
+
|
14
|
+
require 'forwardable'
|
15
|
+
require 'rubygems'
|
16
|
+
require 'oauth'
|
17
|
+
require 'hashie'
|
18
|
+
require 'httparty'
|
19
|
+
|
20
|
+
|
21
|
+
require 'weibo/oauth'
|
22
|
+
require 'weibo/oauth_hack'
|
23
|
+
require 'weibo/httpauth'
|
24
|
+
require 'weibo/request'
|
25
|
+
require 'weibo/config'
|
26
|
+
require 'weibo/base'
|
27
|
+
|
28
|
+
|
3
29
|
module FrankelWeibo
|
4
|
-
|
30
|
+
class WeiboError < StandardError
|
31
|
+
attr_reader :data
|
32
|
+
|
33
|
+
def initialize(data)
|
34
|
+
@data = data
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
class RepeatedWeiboText < WeiboError; end
|
39
|
+
class RateLimitExceeded < WeiboError; end
|
40
|
+
class Unauthorized < WeiboError; end
|
41
|
+
class General < WeiboError; end
|
42
|
+
|
43
|
+
class Unavailable < StandardError; end
|
44
|
+
class InformWeibo < StandardError; end
|
45
|
+
class NotFound < StandardError; end
|
46
|
+
end
|
47
|
+
|
48
|
+
module Hashie
|
49
|
+
class Mash
|
50
|
+
# Converts all of the keys to strings, optionally formatting key name
|
51
|
+
def rubyify_keys!
|
52
|
+
keys.each{|k|
|
53
|
+
v = delete(k)
|
54
|
+
new_key = k.to_s.underscore
|
55
|
+
self[new_key] = v
|
56
|
+
v.rubyify_keys! if v.is_a?(Hash)
|
57
|
+
v.each{|p| p.rubyify_keys! if p.is_a?(Hash)} if v.is_a?(Array)
|
58
|
+
}
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
if File.exists?('config/weibo.yml')
|
67
|
+
weibo_oauth = YAML.load_file('config/weibo.yml')[Rails.env || env || 'development']
|
68
|
+
Weibo::Config.api_key = weibo_oauth["api_key"]
|
69
|
+
Weibo::Config.api_secret = weibo_oauth["api_secret"]
|
70
|
+
else
|
71
|
+
puts "\n\n=========================================================\n\n" +
|
72
|
+
" You haven't made a config/weibo.yml file.\n\n You should. \n\n The weibo gem will work much better if you do\n\n" +
|
73
|
+
" Please set Weibo::Config.api_key and \n Weibo::Config.api_secret\n somewhere in your initialization process\n\n" +
|
74
|
+
"=========================================================\n\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
begin
|
78
|
+
if Rails
|
79
|
+
require 'weibo/railtie'
|
5
80
|
end
|
81
|
+
rescue
|
82
|
+
end
|