stackconnect 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 584521866f19a44852be42c2b887bc195a1a6b4c
4
- data.tar.gz: 62ac6e796de6db00704ddbdea97346ca9a909f8c
3
+ metadata.gz: dd5c160ec1ddce3b067bdb2d49b6e26d74ca496f
4
+ data.tar.gz: 56888108a32e556061fdad166df30084f892099d
5
5
  SHA512:
6
- metadata.gz: 8a7b8cd77e17362026ecf66d7ef953382bdf89c164ddbb5ce6cb95d98e5cc588ea5f755a467fd3500d99da127d6cc74ff77aa42e10f7c41a27df82fc748f5bef
7
- data.tar.gz: 8ac1331b3d950d7e76fb822baeb2d30873b31b666ec3aff5d7f7cf0689e1bb897dc4b45a933c91ea4208eca096a757ed54573aca42ba3e5d48da114db3998bdc
6
+ metadata.gz: 3541ecd06dc2de5f44bbf0ac2a9917acc203e46c750512e9e6e95474087608eebdbe97ceee40e83f91f893a6a56592c002cf5d37ffcec042da7605a8b8a53900
7
+ data.tar.gz: 0668dc199a27a43c9da66017f558648446ee69561a2dd3795e348a5d21a720ce4a276aa27df48053a04620ebb402cbb0e20511db53ba3a5f9085d72f809cb887
data/README.md CHANGED
@@ -1,24 +1,121 @@
1
- # Stack::Connect
1
+ # StackConnect
2
2
 
3
- Ruby API for making StackOverflow queries
3
+ Ruby API for making StackOverflow queries. This is a limited number of the API calls that can be made to the StackOverflow API, and these are all quota limited. So the response you get is not the full amount of data available, just the most popular/highest ranked data based on activity and date.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ In your Gemfile, add this line:
8
8
 
9
- gem 'stack-connect'
9
+ gem 'stackconnect'
10
10
 
11
11
  And then execute:
12
12
 
13
- $ bundle
13
+ $ bundle
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install stack-connect
17
+ $ gem install stackconnect
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO...
21
+ These methods are quota restricted. The Stack Exchange API only allows a quota of 10000 without an API key: http://api.stackexchange.com/docs/authentication. Once you get over that quota without a key, your IP address will be throttled from making any more requests until the next day.
22
+
23
+ ### Retrieve Total Number of Questions
24
+
25
+ `total = StackConnect.retrieve_total_questions(from_date)`
26
+
27
+ This will return an number.
28
+
29
+ From date has to be in Unix date format. So for example, to retrieve the total number of questions from yesterday,
30
+
31
+ ```
32
+ date = Date.today.to_time.to_i
33
+ total = StackConnect.retrieve_total_questions(from_date)
34
+ ```
35
+
36
+ ### Retrieve Most Popular Tags of All Time
37
+
38
+ `data = StackConnect.retrieve_most_popular_tags`
39
+
40
+ This will return a JSON data object which you can then parse. An example:
41
+
42
+ ```
43
+ data["items"].each do |trend|
44
+ puts trend["name"]
45
+ end
46
+ ```
47
+
48
+ The data looks like this:
49
+ ```json
50
+ {
51
+ "items": [
52
+ {
53
+ "has_synonyms": false,
54
+ "is_moderator_only": false,
55
+ "is_required": false,
56
+ "count": 127787,
57
+ "name": "c"
58
+ },
59
+ {
60
+ "has_synonyms": true,
61
+ "is_moderator_only": false,
62
+ "is_required": false,
63
+ "count": 268773,
64
+ "name": "python"
65
+ },
66
+ {
67
+ "has_synonyms": true,
68
+ "is_moderator_only": false,
69
+ "is_required": false,
70
+ "count": 18729,
71
+ "name": "variables"
72
+ },
73
+ ],
74
+ "has_more": true,
75
+ "backoff": 10,
76
+ "quota_max": 10000,
77
+ "quota_remaining": 9973
78
+ }
79
+ ```
80
+
81
+ ### Retrieving the Most Popular Tags of the Day
82
+
83
+ These are sorted based on activity.
84
+
85
+ `data = StackConnect.retrieve_day_popular_tags(from_date)`
86
+
87
+ Sample Data:
88
+
89
+ ```json
90
+ {
91
+ "items": [
92
+ {
93
+ "has_synonyms": false,
94
+ "is_moderator_only": false,
95
+ "is_required": false,
96
+ "count": 1,
97
+ "name": "microsoft-net-http"
98
+ },
99
+ {
100
+ "has_synonyms": false,
101
+ "is_moderator_only": false,
102
+ "is_required": false,
103
+ "count": 1,
104
+ "name": "owin-middleware"
105
+ },
106
+ {
107
+ "has_synonyms": false,
108
+ "is_moderator_only": false,
109
+ "is_required": false,
110
+ "count": 1,
111
+ "name": "mlt"
112
+ },
113
+ ],
114
+ "has_more": true,
115
+ "quota_max": 10000,
116
+ "quota_remaining": 9972
117
+ }
118
+ ```
22
119
 
23
120
  ## Contributing
24
121
 
Binary file
data/lib/stackconnect.rb CHANGED
@@ -5,7 +5,7 @@ require 'uri'
5
5
  class StackConnect
6
6
  attr_accessor :api, :site, :uri
7
7
 
8
- @@VERSION = "0.0.2"
8
+ @@VERSION = "0.0.4"
9
9
  @@api = 'http://api.stackexchange.com/'
10
10
  @@site = 'stackoverflow'
11
11
  @@uri = URI(@@api)
@@ -23,6 +23,12 @@ class StackConnect
23
23
  data = JSON.parse(@@uri.open.read)
24
24
  end
25
25
 
26
+ def retrieve_day_popular_tags(from_date)
27
+ @@uri.path = '/2.1/tags'
28
+ @@uri.query = ({ :fromdate => from_date, :site=>'stackoverflow', :sort => 'activity', :order=>'desc'}).to_query
29
+ data = JSON.parse(@@uri.open.read)
30
+ end
31
+
26
32
  def self.return_version
27
33
  @@VERSION
28
34
  end
data/spec/stack_spec.rb CHANGED
@@ -14,6 +14,10 @@ describe StackConnect do
14
14
  it "retrieve popular tags should return array" do
15
15
  @connect.retrieve_most_popular_tags.should be_a(Hash)
16
16
  end
17
+
18
+ it "retrieve popular tags of the days returns array" do
19
+ date = Date.today.to_time.to_i
20
+ @connect.retrieve_day_popular_tags(date).should be_a(Hash)
21
+ end
17
22
  end
18
23
 
19
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - amirtcheva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-14 00:00:00.000000000 Z
11
+ date: 2014-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber