Class: StackConnect
- Inherits:
-
Object
- Object
- StackConnect
- Defined in:
- lib/stackconnect.rb
Constant Summary collapse
- @@VERSION =
"0.1.7"- @@api =
'http://api.stackexchange.com/'- @@site =
'stackoverflow'- @@api_v =
'/2.2/'- @@uri =
URI(@@api)
- @@earliest_date =
1230793200
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#site ⇒ Object
Returns the value of attribute site.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #form_query(path, args) ⇒ Object
- #parse ⇒ Object
- #retrieve_hot_questions(from_date, page) ⇒ Object
- #retrieve_most_popular_tags ⇒ Object
- #retrieve_tags(from_date) ⇒ Object
- #retrieve_total_questions(from_date) ⇒ Object
- #retrieve_users(page) ⇒ Object
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
5 6 7 |
# File 'lib/stackconnect.rb', line 5 def api @api end |
#site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/stackconnect.rb', line 5 def site @site end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/stackconnect.rb', line 5 def uri @uri end |
Class Method Details
.return_version ⇒ Object
53 54 55 |
# File 'lib/stackconnect.rb', line 53 def self.return_version @@VERSION end |
Instance Method Details
#form_query(path, args) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/stackconnect.rb', line 41 def form_query (path, args) args.merge!(:site=>'stackoverflow') @@uri.path = path @@uri.query = args.to_query puts @@uri parse end |
#parse ⇒ Object
49 50 51 |
# File 'lib/stackconnect.rb', line 49 def parse JSON.parse(@@uri.open.read) end |
#retrieve_hot_questions(from_date, page) ⇒ Object
36 37 38 39 |
# File 'lib/stackconnect.rb', line 36 def retrieve_hot_questions(from_date, page) args = {:fromdate => from_date, :sort=>'hot', :order=>'desc', :page=>page, :pagesize=>100} form_query(@@api_v + 'questions', args) end |
#retrieve_most_popular_tags ⇒ Object
25 26 27 28 |
# File 'lib/stackconnect.rb', line 25 def args = {:sort=>'popular', :order=>'desc'} form_query(@@api_v + 'tags', args) end |
#retrieve_tags(from_date) ⇒ Object
30 31 32 33 34 |
# File 'lib/stackconnect.rb', line 30 def (from_date) raise "Date is too early, must be after January 1, 2009" if from_date < @@earliest_date args = { :fromdate => from_date, :sort=>'popular', :order=>'desc', :page => page } form_query(@@api_v + 'tags', args) end |
#retrieve_total_questions(from_date) ⇒ Object
19 20 21 22 23 |
# File 'lib/stackconnect.rb', line 19 def retrieve_total_questions(from_date) args = {:fromdate=>from_date, :filter => '!--Me6hWI5gUs'} data = form_query(@@api_v + 'questions', args) count = data["total"] end |
#retrieve_users(page) ⇒ Object
14 15 16 17 |
# File 'lib/stackconnect.rb', line 14 def retrieve_users(page) args = {:sort=> 'reputation', :page=>page, :pagesize=> 100, :order=>'desc'} form_query(@@api_v + 'users', args) end |