github-search 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62d7994a724738d0ea8c2af08b5ea162d32810cc
4
+ data.tar.gz: 32edb6b1077d6e9eeaf82517f4a76a31b3d7c339
5
+ SHA512:
6
+ metadata.gz: dd5d8258ae51c2e63e04861369f46894f3e5fdf0218c880084dc9bd34f6824792e2a081943e142d325c67753e9644ece6126d3cbf5bbe47767eba8b68ec63bf7
7
+ data.tar.gz: aee86fb64032a79a56ce459c50a51256670f5b359e54c7457babcd2fdc39d0d52c071ea8d2a9dfc429862d8917b82a9294a25d29862d2e3535e9276ff35b52c5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.1.3"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in githubsearch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Laura Eck
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # GithubSearch
2
+ [![Build Status](https://travis-ci.org/Morred/github-search.svg?branch=master)](https://travis-ci.org/Morred/github-search) [![Code Climate](https://codeclimate.com/github/Morred/github-search/badges/gpa.svg)](https://codeclimate.com/github/Morred/github-search)
3
+
4
+ A wrapper gem for the Github Search API.
5
+
6
+ ### General info
7
+ + The GitHub Search API provides up to 1,000 results for each search.
8
+ + The GitHub Search API has a custom rate limit. For requests using Basic Authentication, OAuth, or client ID and secret, you can make up to 30 requests per minute. For unauthenticated requests, the rate limit allows you to make up to 10 requests per minute.
9
+ + For queries that exceed the time limit, the API returns the matches that were already found prior to the timeout, and the response has the incomplete_results property set to true.
10
+
11
+ See the official documentation for the Github Search API here: https://developer.github.com/v3/search/
12
+
13
+ ## Table of Contents
14
+ 1. [Searching](https://github.com/Morred/github-search#searching)
15
+ + [Searching Issues](https://github.com/Morred/github-search#searching-issues)
16
+ + [Searching Repositories](https://github.com/Morred/github-search#searching-repositories)
17
+ + [Searching Users](https://github.com/Morred/github-search#searching-users)
18
+ + [Searching Code](https://github.com/Morred/github-search#searching-code)
19
+ 2. [Sorting and Ordering](https://github.com/Morred/github-search#sorting-and-ordering)
20
+ + [Sorting Issues](https://github.com/Morred/github-search#sorting-issues)
21
+ + [Sorting Repositories](https://github.com/Morred/github-search#sorting-repositories)
22
+ + [Sorting Users](https://github.com/Morred/github-search#sorting-users)
23
+ + [Ordering](https://github.com/Morred/github-search#ordering)
24
+ 3. [Installation](https://github.com/Morred/github-search#installation)
25
+
26
+ ## Searching
27
+
28
+ Instantiate a new searcher, then use it to search, like so:
29
+
30
+ ```ruby
31
+ github = GithubSearch::Searcher.new
32
+
33
+ result = github.issues.search("test", "issue", repo: "Morred/github-search", label: "enhancement")
34
+ ```
35
+
36
+ You can currently search issues, repositories and users.
37
+
38
+ ### Searching Issues
39
+
40
+ Example:
41
+ ```ruby
42
+ result = github.issues.search("test", "foo", repo: "Morred/github-search", language: "Ruby")
43
+ ```
44
+
45
+ Search for any number of keywords as strings (such as "test" and "foo" in the above example) as well as search qualifiers (such as repo and language in the above example).
46
+
47
+ #### Currently supported issue search qualifiers are:
48
+
49
+ **assignee**
50
+ Finds issues or pull requests that are assigned to a certain user.
51
+ **author**
52
+ Finds issues or pull requests created by a certain user.
53
+ **closed**
54
+ Filters issues or pull requests based on the date when they were closed.
55
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
56
+ **commenter**
57
+ Finds issues or pull requests that a certain user commented on.
58
+ **comments**
59
+ Filters issues or pull requests based on the quantity of comments.
60
+ *Values: e.g. >500, 50..100*
61
+ **created**
62
+ Filters issues or pull requests based on date of creation.
63
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
64
+ **in**
65
+ Qualifies which fields are searched. With this qualifier you can restrict the search to just the title, body, comments, or any combination of these.
66
+ **involves**
67
+ Finds issues or pull requests that were either created by a certain user, assigned to that user, mention that user, or were commented on by that user.
68
+ **is**
69
+ Searches for items within repositories that match a certain state, such as open, closed, or merged.
70
+ *Values: open, closed, unmerged, merged, pr, issue*
71
+ **labels**
72
+ Filters issues or pull requests based on their labels.
73
+ **language**
74
+ Searches for issues or pull requests within repositories that match a certain language.
75
+ *Values: e.g. Ruby, C++, Swift*
76
+ **mentions**
77
+ Finds issues or pull requests that mention a certain user.
78
+ **merged**
79
+ Filters pull requests based on the date when they were merged.
80
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
81
+ **no**
82
+ Filters items missing certain metadata, such as label, milestone, or assignee.
83
+ *Values: label, milestone, assignee*
84
+ **repo**
85
+ Limits searches to a specific repository.
86
+ **state**
87
+ Filter issues or pull requests based on whether they’re open or closed.
88
+ *Values: open, closed*
89
+ **team**
90
+ For organizations you’re a member of, finds issues or pull requests that @mention a team within the organization.
91
+ **type**
92
+ With this qualifier you can restrict the search to issues or pull request only.
93
+ *Values: pr, issue*
94
+ **updated**
95
+ Filters issues or pull requests based on when they were last updated.
96
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
97
+ **user**
98
+ Limits searches to a specific user.
99
+
100
+ ### Searching Repositories
101
+
102
+ Example:
103
+ ```ruby
104
+ result = github.repositories.search("foo", user: "Morred", language: "Ruby")
105
+ ```
106
+
107
+ Search for any number of keywords as strings (such as "foo" in the above example) as well as search qualifiers (such as user and language in the above example).
108
+
109
+ #### Currently supported repository search qualifiers are:
110
+
111
+ **created**
112
+ Filters repositories based on date of creation.
113
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
114
+ **forks**
115
+ Filters repositories based on the number of forks, and/or whether forked repositories should be included in the results at all.
116
+ **in**
117
+ Qualifies which fields are searched. With this qualifier you can restrict the search to just the repository name, description, readme, or any combination of these.
118
+ *Values: name, description, readme*
119
+ **language**
120
+ Searches repositories based on the language they’re written in.
121
+ *Values: e.g. Ruby, C++, Swift*
122
+ **pushed**
123
+ Filters repositories based on when they were last updated.
124
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
125
+ **size**
126
+ Finds repositories that match a certain size (in kilobytes).
127
+ **stars**
128
+ Searches repositories based on the number of stars.
129
+ **user**
130
+ Limits searches to a specific user.
131
+
132
+ ### Searching Users
133
+
134
+ Example:
135
+ ```ruby
136
+ result = github.users.search("morred", repos: ">10", language: "Ruby")
137
+ ```
138
+
139
+ Search for any number of keywords as strings (such as "morred" in the above example) as well as search qualifiers (such as repos and language in the above example).
140
+
141
+ #### Currently supported user search qualifiers are:
142
+
143
+ **created**
144
+ Filter users based on when they joined.
145
+ *Values: e.g. >2014-12-25, <=2015-01-17, 2019-02-03*
146
+
147
+ **followers**
148
+ Filter users based on the number of followers they have.
149
+ **in**
150
+ Qualifies which fields are searched. With this qualifier you can restrict the search to just the username, public email, full name, or any combination of these.
151
+ **language**
152
+ Search for users that have repositories that match a certain language.
153
+ *Values: e.g. Ruby, C++, Swift*
154
+ **location**
155
+ Filter users by the location indicated in their profile.
156
+ *Values: e.g. Germany, Tokyo*
157
+ **repos**
158
+ Filters users based on the number of repositories they have.
159
+ *Values: e.g. 20, >10, <100*
160
+ **type**
161
+ With this qualifier you can restrict the search to just personal accounts or just organization accounts.
162
+ *Values: User, Organization*
163
+
164
+ ### Searching Code
165
+
166
+ **TODO**
167
+
168
+ ## Sorting and Ordering
169
+
170
+ Example:
171
+ ```ruby
172
+ result = github.repositories.search("test", user: "Morred", sort: :stars, order: :asc)
173
+ ```
174
+
175
+ **By default, all results are sorted by best match. The default order is descending.**
176
+
177
+ ### Sorting Issues
178
+
179
+ Issues can be sorted by:
180
+
181
+ **comments**
182
+ Issues are sorted by comments count.
183
+
184
+ **created**
185
+ Issues are sorted by their created_at date.
186
+
187
+ **updated**
188
+ Issues are sorted by their updated_at date.
189
+
190
+ ### Sorting Repositories
191
+
192
+ Repositories can be sorted by:
193
+
194
+ **stars**
195
+ Repositories are sorted by stars count.
196
+
197
+ **forks**
198
+ Repositories are sorted by forks count.
199
+
200
+ **updated**
201
+ Somewhat counterintuitively, repositories are *not* sorted by updated_at, but instead by pushed_at.
202
+
203
+ ### Sorting Users
204
+
205
+ Users can be sorted by:
206
+
207
+ **followers**
208
+ Users are sorted by followers count.
209
+
210
+ **repositories**
211
+ Users are sorted by repositories count.
212
+
213
+ **joined**
214
+ Users are sorted by their joined_at date.
215
+
216
+ ### Ordering
217
+
218
+ You can only order your search results when a sort parameter is provided.
219
+
220
+ **asc**
221
+ Ascending order.
222
+
223
+ **desc**
224
+ Descending order.
225
+
226
+ The default order is descending.
227
+
228
+ ## Installation
229
+
230
+ Add this line to your application's Gemfile:
231
+
232
+ ```ruby
233
+ gem 'github-search'
234
+ ```
235
+
236
+ And then execute:
237
+
238
+ $ bundle
239
+
240
+ Or install it yourself as:
241
+
242
+ $ gem install github-search
243
+
244
+ ## Contributing
245
+
246
+ 1. Fork it ( https://github.com/Morred/github-search/fork )
247
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
248
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
249
+ 4. Push to the branch (`git push origin my-new-feature`)
250
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "spec"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task :default => 'test'
10
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'github-search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "github-search"
8
+ spec.version = GithubSearch::VERSION
9
+ spec.authors = ["Laura Eck"]
10
+ spec.email = ["laura.tatsutahime@gmail.com"]
11
+ spec.summary = %q{A wrapper for the Github Search API}
12
+ spec.description = %q{This gem wraps the Github Search API and allows you to search users, repositories and issues}
13
+ spec.homepage = "https://github.com/Morred/github-search"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", '~> 5.5'
24
+ spec.add_development_dependency "vcr", "~> 2.9"
25
+ spec.add_development_dependency "webmock", "~> 1.20"
26
+
27
+ spec.add_dependency "faraday", "~> 0.9"
28
+ spec.add_dependency "json", "~> 1.8"
29
+ end
@@ -0,0 +1,12 @@
1
+ require "github-search/version"
2
+ require "github-search/searcher"
3
+ require "github-search/search_string_builder"
4
+ require "github-search/issue"
5
+ require "github-search/repository"
6
+ require "github-search/user"
7
+
8
+ module GithubSearch
9
+
10
+ API_URL = "https://api.github.com/search"
11
+
12
+ end
@@ -0,0 +1,55 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module GithubSearch
5
+ class Issue < Searcher
6
+ attr_reader :id,
7
+ :number,
8
+ :title,
9
+ :body,
10
+ :url,
11
+ :labels_url,
12
+ :comments_url,
13
+ :events_url,
14
+ :html_url,
15
+ :user,
16
+ :labels,
17
+ :state,
18
+ :locked,
19
+ :assignee,
20
+ :milestone,
21
+ :comments,
22
+ :created_at,
23
+ :updated_at,
24
+ :closed_at,
25
+ :score
26
+
27
+ def initialize(attributes)
28
+ @id = attributes["id"]
29
+ @number = attributes["number"]
30
+ @title = attributes["title"]
31
+ @body = attributes["body"]
32
+ @url = attributes["url"]
33
+ @labels_url = attributes["labels_url"]
34
+ @comments_url = attributes["comments_url"]
35
+ @events_url = attributes["events_url"]
36
+ @html_url = attributes["html_url"]
37
+ @user = attributes["user"]
38
+ @labels = attributes["labels"]
39
+ @state = attributes["state"]
40
+ @locked = attributes["locked"]
41
+ @assignee = attributes["assignee"]
42
+ @milestone = attributes["milestone"]
43
+ @comments = attributes["comments"]
44
+ @created_at = attributes["created_at"]
45
+ @updated_at = attributes["updated_at"]
46
+ @closed_at = attributes["closed_at"]
47
+ @score = attributes["score"]
48
+ end
49
+
50
+ def self.sort_options
51
+ [:comments, :created, :updated]
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,151 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module GithubSearch
5
+ class Repository < Searcher
6
+ attr_reader :id,
7
+ :name,
8
+ :full_name,
9
+ :owner,
10
+ :private,
11
+ :html_url,
12
+ :description,
13
+ :fork,
14
+ :url,
15
+ :forks_url,
16
+ :keys_url,
17
+ :collaborators_url,
18
+ :teams_url,
19
+ :hooks_url,
20
+ :issue_events_url,
21
+ :events_url,
22
+ :assignees_url,
23
+ :branches_url,
24
+ :tags_url,
25
+ :blobs_url,
26
+ :git_tags_url,
27
+ :git_refs_url,
28
+ :trees_url,
29
+ :statuses_url,
30
+ :languages_url,
31
+ :stargazers_url,
32
+ :contributors_url,
33
+ :subscribers_url,
34
+ :subscription_url,
35
+ :commits_url,
36
+ :git_commits_url,
37
+ :comments_url,
38
+ :issue_comment_url,
39
+ :contents_url,
40
+ :compare_url,
41
+ :merges_url,
42
+ :archive_url,
43
+ :downloads_url,
44
+ :issues_url,
45
+ :pulls_url,
46
+ :milestones_url,
47
+ :notifications_url,
48
+ :labels_url,
49
+ :releases_url,
50
+ :created_at,
51
+ :updated_at,
52
+ :pushed_at,
53
+ :git_url,
54
+ :ssh_url,
55
+ :clone_url,
56
+ :svn_url,
57
+ :homepage,
58
+ :size,
59
+ :stargazers_count,
60
+ :watchers_count,
61
+ :language,
62
+ :has_issues,
63
+ :has_downloads,
64
+ :has_wiki,
65
+ :has_pages,
66
+ :forks_count,
67
+ :mirror_url,
68
+ :open_issues_count,
69
+ :forks,
70
+ :open_issues,
71
+ :watchers,
72
+ :default_branch,
73
+ :score
74
+
75
+ def initialize(attributes)
76
+ @id = attributes["id"]
77
+ @name = attributes["name"]
78
+ @full_name = attributes["full_name"]
79
+ @owner = attributes["owner"]
80
+ @private = attributes["private"]
81
+ @html_url = attributes["html_url"]
82
+ @description = attributes["description"]
83
+ @fork = attributes["fork"]
84
+ @url = attributes["url"]
85
+ @forks_url = attributes["forks_url"]
86
+ @keys_url = attributes["keys_url"]
87
+ @collaborators_url = attributes["collaborators_url"]
88
+ @teams_url = attributes["teams_url"]
89
+ @hooks_url = attributes["hooks_url"]
90
+ @issue_events_url = attributes["issue_events_url"]
91
+ @events_url = attributes["events_url"]
92
+ @assignees_url = attributes["assignees_url"]
93
+ @branches_url = attributes["branches_url"]
94
+ @tags_url = attributes["tags_url"]
95
+ @blobs_url = attributes["blobs_url"]
96
+ @git_tags_url = attributes["git_tags_url"]
97
+ @git_refs_url = attributes["git_refs_url"]
98
+ @trees_url = attributes["trees_url"]
99
+ @statuses_url = attributes["statuses_url"]
100
+ @languages_url = attributes["languages_url"]
101
+ @stargazers_url = attributes["stargazers_url"]
102
+ @contributors_url = attributes["contributors_url"]
103
+ @subscribers_url = attributes["subscribers_url"]
104
+ @subscription_url = attributes["subscription_url"]
105
+ @commits_url = attributes["commits_url"]
106
+ @git_commits_url = attributes["git_commits_url"]
107
+ @comments_url = attributes["comments_url"]
108
+ @issue_comment_url = attributes["issue_comment_url"]
109
+ @contents_url = attributes["contents_url"]
110
+ @compare_url = attributes["compare_url"]
111
+ @merges_url = attributes["merges_url"]
112
+ @archive_url = attributes["archive_url"]
113
+ @downloads_url = attributes["downloads_url"]
114
+ @issues_url = attributes["issues_url"]
115
+ @pulls_url = attributes["pulls_url"]
116
+ @milestones_url = attributes["milestones_url"]
117
+ @notifications_url = attributes["notifications_url"]
118
+ @labels_url = attributes["labels_url"]
119
+ @releases_url = attributes["releases_url"]
120
+ @created_at = attributes["created_at"]
121
+ @updated_at = attributes["updated_at"]
122
+ @pushed_at = attributes["pushed_at"]
123
+ @git_url = attributes["git_url"]
124
+ @ssh_url = attributes["ssh_url"]
125
+ @clone_url = attributes["clone_url"]
126
+ @svn_url = attributes["svn_url"]
127
+ @homepage = attributes["homepage"]
128
+ @size = attributes["size"]
129
+ @stargazers_count = attributes["stargazers_count"]
130
+ @watchers_count = attributes["watchers_count"]
131
+ @language = attributes["language"]
132
+ @has_issues = attributes["has_issues"]
133
+ @has_downloads = attributes["has_downloads"]
134
+ @has_wiki = attributes["has_wiki"]
135
+ @has_pages = attributes["has_pages"]
136
+ @forks_count = attributes["forks_count"]
137
+ @mirror_url = attributes["mirror_url"]
138
+ @open_issues_count = attributes["open_issues_count"]
139
+ @forks = attributes["forks"]
140
+ @open_issues = attributes["open_issues"]
141
+ @watchers = attributes["watchers"]
142
+ @default_branch = attributes["default_branch"]
143
+ @score = attributes["score"]
144
+ end
145
+
146
+ def self.sort_options
147
+ [:stars, :forks, :updated]
148
+ end
149
+
150
+ end
151
+ end