Class: StackConnect

Inherits:
Object
  • Object
show all
Defined in:
lib/stackconnect.rb

Constant Summary collapse

@@VERSION =
"0.1.6"
@@api =
'http://api.stackexchange.com/'
@@site =
'stackoverflow'
@@api_v =
'/2.2/'
@@uri =
URI(@@api)
@@earliest_date =
1230793200

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject

Returns the value of attribute api.



6
7
8
# File 'lib/stackconnect.rb', line 6

def api
  @api
end

#siteObject

Returns the value of attribute site.



6
7
8
# File 'lib/stackconnect.rb', line 6

def site
  @site
end

#uriObject

Returns the value of attribute uri.



6
7
8
# File 'lib/stackconnect.rb', line 6

def uri
  @uri
end

Class Method Details

.return_versionObject



54
55
56
# File 'lib/stackconnect.rb', line 54

def self.return_version
  @@VERSION
end

Instance Method Details

#form_query(path, args) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/stackconnect.rb', line 42

def form_query (path, args)
  args.merge!(:site=>'stackoverflow')
  @@uri.path = path
  @@uri.query = args.to_query
  puts @@uri
  parse
end

#parseObject



50
51
52
# File 'lib/stackconnect.rb', line 50

def parse
  JSON.parse(@@uri.open.read)
end

#retrieve_hot_questions(from_date, page) ⇒ Object



37
38
39
40
# File 'lib/stackconnect.rb', line 37

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


26
27
28
29
# File 'lib/stackconnect.rb', line 26

def retrieve_most_popular_tags
  args = {:sort=>'popular', :order=>'desc'}
  form_query(@@api_v + 'tags', args)
end

#retrieve_tags(from_date) ⇒ Object



31
32
33
34
35
# File 'lib/stackconnect.rb', line 31

def retrieve_tags(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



20
21
22
23
24
# File 'lib/stackconnect.rb', line 20

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



15
16
17
18
# File 'lib/stackconnect.rb', line 15

def retrieve_users(page)
  args = {:sort=> 'reputation', :page=>page, :pagesize=> 100, :order=>'desc'}
  form_query(@@api_v + 'users', args)
end