tida_sina_weibo 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,6 @@ module TidaSinaWeibo
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("../../templates", __FILE__)
5
5
 
6
- desc "Creates a Devise initializer and copy locale files to your application."
7
- class_option :orm
8
-
9
6
  def copy_settings
10
7
  copy_file "../../../config/tida_sina_weibo.yml", "config/tida_sina_weibo.yml"
11
8
  end
@@ -0,0 +1,9 @@
1
+ require 'settingslogic'
2
+ require 'rails'
3
+
4
+ module TidaSinaWeibo
5
+ class ApiSettings < ::Settingslogic
6
+ source "#{Rails.root}/config/tida_sina_weibo.yml"
7
+ namespace Rails.env
8
+ end
9
+ end
@@ -1,29 +1,8 @@
1
1
  require "rest-client"
2
+ require 'tida_sina_weibo/api_settings'
2
3
 
3
4
  module TidaSinaWeibo
4
5
 
5
- API = {}
6
- API[:status] = {}
7
- API[:status][:update] = 'https://api.weibo.com/2/statuses/update.json'
8
- API[:status][:upload] = 'https://upload.api.weibo.com/2/statuses/upload.json'
9
- API[:status][:user_timeline] = 'https://api.weibo.com/2/statuses/user_timeline.json'
10
- API[:status][:user_timeline_ids] = 'https://api.weibo.com/2/statuses/user_timeline/ids.json'
11
- API[:status][:show] = 'https://api.weibo.com/2/statuses/show.json'
12
- API[:status][:repost_timeline] = 'https://api.weibo.com/2/statuses/repost_timeline.json'
13
- API[:status][:repost_timeline_ids] = 'https://api.weibo.com/2/statuses/repost_timeline/ids.json'
14
- API[:status][:queryid] = 'https://api.weibo.com/2/statuses/queryid.json'
15
- API[:status][:querymid] = 'https://api.weibo.com/2/statuses/querymid.json'
16
- API[:comments] = {}
17
- API[:comments][:show] = 'https://api.weibo.com/2/comments/show.json'
18
- API[:user] = {}
19
- API[:user][:show] = 'https://api.weibo.com/2/users/show.json'
20
- API[:user][:domain_show] = 'https://api.weibo.com/2/users/domain_show.json'
21
- API[:tags] = 'https://api.weibo.com/2/tags.json'
22
- API[:friendships] = {}
23
- API[:friendships][:followers] = 'https://api.weibo.com/2/friendships/followers.json'
24
- API[:friendships][:followers_ids] = 'https://api.weibo.com/2/friendships/followers/ids.json'
25
- API[:friendships][:show] = 'https://api.weibo.com/2/friendships/show.json'
26
-
27
6
  class ApiWrapper
28
7
 
29
8
  attr_reader :access_token
@@ -31,66 +10,67 @@ module TidaSinaWeibo
31
10
  attr_reader :token_provider
32
11
  attr_reader :rest_client
33
12
 
34
- def initialize(rest_client, tp)
35
- @rest_client = rest_client
13
+ def initialize(tp, rc = nil)
14
+ rc = RestClientWrapper.new if rc.nil?
15
+ @rest_client = rc
36
16
  @token_provider = tp
37
17
  @access_token = tp.token
38
18
  end
39
19
 
40
20
  def status_update(content)
41
- post_request(API[:status][:update], :status => content)
21
+ post_request(ApiSettings.weibo.api.status.update, :status => content)
42
22
  end
43
23
 
44
24
  def status_upload(content, image_path)
45
- post_request(API[:status][:upload], :status => content, :pic => File.new(image_path, 'rb'))
25
+ post_request(ApiSettings.weibo.api.status.upload, :status => content, :pic => File.new(image_path, 'rb'))
46
26
  end
47
27
 
48
28
  def status_user_timeline(uid, page = 1, count = 100)
49
- get_request(API[:status][:user_timeline], :params => {:uid => uid, :page => page, :count => count})
29
+ get_request(ApiSettings.weibo.api.status.user_timeline, :params => {:uid => uid, :page => page, :count => count})
50
30
  end
51
31
 
52
32
  def status_repost_timeline(post_id, page = 1)
53
- get_request(API[:status][:repost_timeline], :params => {:id => post_id, :page => page, :count => 50})
33
+ get_request(ApiSettings.weibo.api.status.repost_timeline, :params => {:id => post_id, :page => page, :count => 50})
54
34
  end
55
35
 
56
36
  def comments_show(post_id, page = 1)
57
- get_request(API[:comments][:show], :params => {:id => post_id, :page => page, :count => 50})
37
+ get_request(ApiSettings.weibo.api.comments.show, :params => {:id => post_id, :page => page, :count => 50})
58
38
  end
59
39
 
60
40
  def status_show(wb_post_id)
61
- get_request(API[:status][:show], :params => {:id => wb_post_id})
41
+ get_request(ApiSettings.weibo.api.status.show, :params => {:id => wb_post_id})
62
42
  end
63
43
 
64
44
  def user_show(uid, is_number_id = true)
65
45
  if is_number_id
66
- get_request(API[:user][:show], {:params => {:uid => uid}})
46
+ get_request(ApiSettings.weibo.api.user.show, {:params => {:uid => uid}})
67
47
  else
68
- get_request(API[:user][:show], {:params => {:screen_name => uid}})
48
+ get_request(ApiSettings.weibo.api.user.show, {:params => {:screen_name => uid}})
69
49
  end
70
50
  end
71
51
 
72
52
  def user_domain_show(domain)
73
- get_request(API[:user][:domain_show], :params => {:domain => domain})
53
+ get_request(ApiSettings.weibo.api.user.domain_show, :params => {:domain => domain})
74
54
  end
75
55
 
76
56
  def friendships_followers(uid, cursor)
77
- get_request(API[:friendships][:followers], :params => {:uid => uid, :cursor => cursor})
57
+ get_request(ApiSettings.weibo.api.friendships.followers, :params => {:uid => uid, :cursor => cursor})
78
58
  end
79
59
 
80
60
  def friendships_followers_ids(uid, cursor)
81
- get_request(API[:friendships][:followers_ids], :params => {:uid => uid, :cursor => cursor})
61
+ get_request(ApiSettings.weibo.api.friendships.followers_ids, :params => {:uid => uid, :cursor => cursor})
82
62
  end
83
63
 
84
64
  def tags(uid)
85
- get_request(API[:tags], :params => {:uid => uid})
65
+ get_request(ApiSettings.weibo.api.tags, :params => {:uid => uid})
86
66
  end
87
67
 
88
68
  def queryid(mid)
89
- get_request(API[:status][:queryid], {:params => {:mid => mid, :type => 1, :isBase62 => 1}})
69
+ get_request(ApiSettings.weibo.api.status.queryid, {:params => {:mid => mid, :type => 1, :isBase62 => 1}})
90
70
  end
91
71
 
92
72
  def querymid(id, batch = false)
93
- get_request(API[:status][:querymid], {:params => {:id => id, :type => 1, :is_batch => batch ? 1 : 0}})
73
+ get_request(ApiSettings.weibo.api.status.querymid, {:params => {:id => id, :type => 1, :is_batch => batch ? 1 : 0}})
94
74
  end
95
75
 
96
76
  def querymids(ids)
@@ -1,3 +1,3 @@
1
1
  module TidaSinaWeibo
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,7 +2,7 @@ require 'tida_sina_weibo'
2
2
 
3
3
  describe TidaSinaWeibo::ApiWrapper do
4
4
  it 'get setting property' do
5
- TidaSinaWeibo::API[:status][:update].should eql('https://api.weibo.com/2/statuses/update.json')
5
+ # ApiSettings.should eql('https://api.weibo.com/2/statuses/update.json')
6
6
  end
7
7
 
8
8
  it 'get request success' do
@@ -12,7 +12,7 @@ describe TidaSinaWeibo::ApiWrapper do
12
12
  token_provider = double('token_provider')
13
13
  token_provider.stub(:token) { 'token'}
14
14
 
15
- target = TidaSinaWeibo::ApiWrapper.new request_wrapper, token_provider
15
+ target = TidaSinaWeibo::ApiWrapper.new token_provider, request_wrapper
16
16
  result = target.status_show '1'
17
17
  result.should eql({'result' =>'ok'})
18
18
  end
@@ -30,7 +30,7 @@ describe TidaSinaWeibo::ApiWrapper do
30
30
  token_provider.stub(:change)
31
31
  token_provider.stub(:token) { nil }
32
32
 
33
- target = TidaSinaWeibo::ApiWrapper.new request_wrapper, token_provider
33
+ target = TidaSinaWeibo::ApiWrapper.new token_provider, request_wrapper
34
34
  begin
35
35
  result = target.status_show '1'
36
36
  raise 'Expect exception raise'
@@ -51,7 +51,7 @@ describe TidaSinaWeibo::ApiWrapper do
51
51
  token_provider.stub(:change)
52
52
  token_provider.stub(:token) { nil }
53
53
 
54
- target = TidaSinaWeibo::ApiWrapper.new request_wrapper, token_provider
54
+ target = TidaSinaWeibo::ApiWrapper.new token_provider, request_wrapper
55
55
  begin
56
56
  result = target.status_show '1'
57
57
  raise 'Expect exception raise'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tida_sina_weibo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -78,6 +78,7 @@ files:
78
78
  - lib/generators/tida_sina_weibo/.DS_Store
79
79
  - lib/generators/tida_sina_weibo/install_generator.rb
80
80
  - lib/tida_sina_weibo.rb
81
+ - lib/tida_sina_weibo/api_settings.rb
81
82
  - lib/tida_sina_weibo/api_wrapper.rb
82
83
  - lib/tida_sina_weibo/exceptions.rb
83
84
  - lib/tida_sina_weibo/rest_client_wrapper.rb