Class: StackConnect

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject

Returns the value of attribute api.



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

def api
  @api
end

#siteObject

Returns the value of attribute site.



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

def site
  @site
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.return_versionObject



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

#parseObject



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


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

def retrieve_most_popular_tags
  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 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



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