Class: StackConnect

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

Constant Summary collapse

@@VERSION =
"0.1.2"
@@api =
'http://api.stackexchange.com/'
@@site =
'stackoverflow'
@@uri =
URI(@@api)

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



56
57
58
# File 'lib/stackconnect.rb', line 56

def self.return_version
  @@VERSION
end

Instance Method Details

#form_query(path, args) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/stackconnect.rb', line 44

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

#parseObject



52
53
54
# File 'lib/stackconnect.rb', line 52

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

#retrieve_hot_questions(from_date, page) ⇒ Object



39
40
41
42
# File 'lib/stackconnect.rb', line 39

def retrieve_hot_questions(from_date, page)
  args = {:fromdate => from_date, :sort=>'hot', :order=>'desc', :page=>page, :pagesize=>100}
  form_query('/2.1/questions', args)
end


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

def retrieve_most_popular_tags
  args = {:sort=>'popular', :order=>'desc'}
  form_query('/2.1/tags', args)
end

#retrieve_tags(from_date, to_date, page) ⇒ Object



29
30
31
32
# File 'lib/stackconnect.rb', line 29

def retrieve_tags(from_date)
  args = { :fromdate => from_date, :sort=>'activity', :order=>'desc'}
  form_query('/2.1/tags', args)
end

#retrieve_total_questions(from_date) ⇒ Object



18
19
20
21
22
# File 'lib/stackconnect.rb', line 18

def retrieve_total_questions(from_date)
  args = {:fromdate=>from_date, :filter => '!--Me6hWI5gUs'}
  data = form_query('/2.1/questions', args) 
  count = data["total"]
end

#retrieve_users(page) ⇒ Object



13
14
15
16
# File 'lib/stackconnect.rb', line 13

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