github_api 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,16 +14,6 @@ Supports all the API methods(nearly 200). It's build in a modular way, that is,
14
14
  ## Important!!
15
15
  Since version 0.5 the way the gem queries the GitHub api underwent important changes. It closely mirros the Github api hierarchy e.i. if you want to create a download resource, lookup the github api spec and issue the request as in `github.repos.downloads.create`
16
16
 
17
- ```ruby
18
- Old style: github.pull_requests.create_request
19
- github.pull_requests.pull_requests
20
- github.pull_requests.pull_request
21
-
22
- New style: github.pull_requests.create
23
- github.pull_requests.all
24
- github.pull_requests.find
25
- ```
26
-
27
17
  ## Installation
28
18
 
29
19
  Install the gem by issuing
@@ -46,12 +36,22 @@ Create a new client instance
46
36
  github = Github.new
47
37
  ```
48
38
 
49
- At this stage you can also supply various configuration parameters, such as `:user`,`:repo`, `:org`, `:oauth_token`, `:login`, `:password` or `:basic_auth` which are used throughout the API
39
+ At this stage you can also supply various configuration parameters, such as `:user`,`:repo`, `:org`, `:oauth_token`, `:basic_auth`, `:endpoint` which are used throughout the API. These can be passed directly as hash options:
50
40
 
51
41
  ```ruby
52
42
  github = Github.new oauth_token: 'token'
53
43
  ```
54
44
 
45
+ Alternatively, you can configure the Github settings by passing a block, for instance, with custom enteprise endpoint like
46
+
47
+ ```ruby
48
+ github = Github.new do |config|
49
+ config.endpoint = 'https://github.company.com/api/v3'
50
+ config.oauth_token = 'token'
51
+ config.adapter = :net_http
52
+ end
53
+ ```
54
+
55
55
  You can authenticate either using OAuth authentication convenience methods(see section OAuth) or through basic authentication by passing your login and password credentials
56
56
 
57
57
  ```ruby
@@ -88,6 +88,29 @@ repos.branches do |branch|
88
88
  end
89
89
  ```
90
90
 
91
+ ## Inputs
92
+
93
+ Some API methods apart from required parameters such as username, repository name
94
+ or organisation name, allow you to switch the way the data is returned to you, for instance
95
+
96
+ ```ruby
97
+ github = Github.new
98
+ github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea'
99
+ # => gets a tree
100
+
101
+ github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea',
102
+ recursive: true # => gets a whole tree recursively
103
+ ```
104
+
105
+ by passing a block you can iterate over the file tree
106
+
107
+ ```ruby
108
+ github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea',
109
+ recursive: true do |file|
110
+ puts file.path
111
+ end
112
+ ```
113
+
91
114
  ## API
92
115
 
93
116
  Main API methods are grouped into the following classes that can be instantiated on their own
@@ -116,72 +139,29 @@ github.users.followers.following 'wycats' # => returns true if following, otherw
116
139
  ```
117
140
 
118
141
  For specification on all available methods go to http://developer.github.com/v3/ or
119
- read the rdoc, all methods are documented there with examples of usage.
120
-
121
- Alternatively, you can find out a specific class supported methods by calling `actions` in your `irb`:
122
-
123
- ```ruby
124
- >> Github::Repos.actions
125
- ---
126
- |--> all
127
- |--> branches
128
- |--> collaborators
129
- |--> commits
130
- |--> contribs
131
- |--> contributors
132
- |--> create
133
- |--> downloads
134
- |--> edit
135
- |--> find
136
- |--> forks
137
- |--> get
138
- |--> hooks
142
+ read the rdoc, all methods are documented there with examples of usage.
143
+
144
+ Alternatively, you can find out supported methods by calling `actions` on a class instance in your `irb`:
145
+
146
+ ```ruby
147
+ >> Github::Repos.actions >> github.issues.actions
148
+ --- ---
149
+ |--> all |--> all
150
+ |--> branches |--> comments
151
+ |--> collaborators |--> create
152
+ |--> commits |--> edit
153
+ |--> contribs |--> events
154
+ |--> contributors |--> find
155
+ |--> create |--> get
156
+ |--> downloads |--> labels
157
+ |--> edit |--> list
158
+ |--> find |--> list_repo
159
+ |--> forks |--> list_repository
160
+ |--> get |--> milestones
161
+ |--> hooks ...
139
162
  ...
140
163
  ```
141
164
 
142
- or you can call `actions` on chained query:
143
-
144
- ```
145
- >> github.issues.actions
146
- ---
147
- |--> all
148
- |--> comments
149
- |--> create
150
- |--> edit
151
- |--> events
152
- |--> find
153
- |--> get
154
- |--> labels
155
- |--> list
156
- |--> list_repo
157
- |--> list_repository
158
- |--> milestones
159
- ---
160
- ```
161
-
162
- ## Inputs
163
-
164
- Some API methods apart from required parameters such as username, repository name
165
- or organisation name, allow you to switch the way the data is returned to you, for instance
166
-
167
- ```ruby
168
- github = Github.new
169
- github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea'
170
- # => gets a tree
171
-
172
- github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea',
173
- recursive: true # => gets a whole tree recursively
174
- ```
175
-
176
- by passing a block you can iterate over the file tree
177
-
178
- ```ruby
179
- github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea',
180
- recursive: true do |file|
181
- puts file.path
182
- end
183
- ```
184
-
185
165
  ## OAuth
186
166
 
187
167
  In order to authenticate the user through OAuth2 on GitHub you need to
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://<BASIC_AUTH>@api.github.com/repos/wycats/thor/git/tags/ffbc56c0c2?access_token=<TOKEN>
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3.raw+json,application/vnd.github.beta.raw+json;q=0.5,application/json;q=0.1
12
+ Accept-Charset:
13
+ - utf-8
14
+ User-Agent:
15
+ - Github Ruby Gem 0.6.1
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: Not Found
24
+ headers:
25
+ Server:
26
+ - nginx/1.0.13
27
+ Date:
28
+ - Wed, 11 Jul 2012 21:35:36 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 404 Not Found
37
+ X-Ratelimit-Limit:
38
+ - '5000'
39
+ Cache-Control:
40
+ - ''
41
+ X-Ratelimit-Remaining:
42
+ - '4999'
43
+ Content-Encoding:
44
+ - gzip
45
+ body:
46
+ encoding: ASCII-8BIT
47
+ string: !binary |-
48
+ H4sIAAAAAAAAA6tWyk0tLk5MT1WyUvLLL1Fwyy/NS1GqBQB8+Ys1FwAAAA==
49
+ http_version: !!null
50
+ recorded_at: Wed, 11 Jul 2012 21:35:36 GMT
51
+ recorded_with: VCR 2.2.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://<BASIC_AUTH>@api.github.com/markdown?access_token=<TOKEN>
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{\"text\":\"Hello world\",\"mode\":\"gfm\",\"context\":\"<USER>/github_api_test\"}"
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.0.13
23
+ Date:
24
+ - Sun, 01 Jul 2012 19:15:21 GMT
25
+ Content-Type:
26
+ - text/html;charset=utf-8
27
+ Connection:
28
+ - keep-alive
29
+ Status:
30
+ - 200 OK
31
+ Content-Length:
32
+ - "18"
33
+ X-Ratelimit-Remaining:
34
+ - "4998"
35
+ Etag:
36
+ - "\"4114864e259a6fdcc545904ac07b9885\""
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Ratelimit-Limit:
40
+ - "5000"
41
+ body:
42
+ encoding: US-ASCII
43
+ string: <p>Hello world</p>
44
+ http_version:
45
+ recorded_at: Sun, 01 Jul 2012 19:15:21 GMT
46
+ recorded_with: VCR 2.2.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://<BASIC_AUTH>@api.github.com/markdown/raw?access_token=<TOKEN>
6
+ body:
7
+ encoding: UTF-8
8
+ string: Hello cool world
9
+ headers:
10
+ Content-Type:
11
+ - text/plain
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.0.13
23
+ Date:
24
+ - Mon, 02 Jul 2012 21:12:15 GMT
25
+ Content-Type:
26
+ - text/html;charset=utf-8
27
+ Connection:
28
+ - keep-alive
29
+ Status:
30
+ - 200 OK
31
+ X-Ratelimit-Limit:
32
+ - "5000"
33
+ Content-Length:
34
+ - "23"
35
+ Etag:
36
+ - "\"a79261d735e1ecdd6566a15f02a46e21\""
37
+ X-Ratelimit-Remaining:
38
+ - "4999"
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ body:
42
+ encoding: US-ASCII
43
+ string: <p>Hello cool world</p>
44
+ http_version:
45
+ recorded_at: Mon, 02 Jul 2012 21:12:16 GMT
46
+ recorded_with: VCR 2.2.0
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://<BASIC_AUTH>@api.github.com/repos/peter-murach/github/branches/new_dsl?access_token=<TOKEN>
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.0.13
23
+ Date:
24
+ - Fri, 29 Jun 2012 20:55:08 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 200 OK
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ X-Ratelimit-Limit:
36
+ - "5000"
37
+ Etag:
38
+ - "\"9671c6f2ca93115c89db73e8e95a228d\""
39
+ X-Ratelimit-Remaining:
40
+ - "4999"
41
+ Content-Encoding:
42
+ - gzip
43
+ body:
44
+ encoding: ASCII-8BIT
45
+ string: !binary |
46
+ H4sIAAAAAAAAA+1US2/UMBD+K6tI3LqJ7TgPR0LAhRsSB24IrSb25KHdPGQ7
47
+ cKj2vzPuNm2KEF1aceOUicbz+Ob7Zm4jPQ1D76PqNnIdRFXUlCJtijSTwLgo
48
+ S6gzA8pgIzAXWok0z2tINcjoZhPqLeJjihoxb4TiGXDF0wwEN4IhpYBUFUrq
49
+ tDYFaFZTisWeqGbn/eyqJIG5j9ved0sdU1uJxXlyyYwe7X5YLOguuXjDJwk1
50
+ XXJ1rfNNNKBz0FKj0Qdjds1kB/C+H9tg7pwHfdz1YzPF1BcsvptsgGTAhwhB
51
+ 09gzuRflF1ZWklei3LOiYowe4wB9gDFfmnzfhv+AgHwjDCH8cz95u/t0ByKi
52
+ Vl6B+0KYS/6aKBrjvwJEiB4nBt/Bgz08hehQLxbj1l68d/xezKSphVQmy3KS
53
+ XFPqDFidK2Sm4CYrlVTvzNsHgQhZxhjDEWjE8Yg+AefQu41q3oiP/UAsOzLW
54
+ alt7zyWL57Elbk5T24+Bt43CntPk4tA+1SRFrHUOvQkb9AweCgjvpJQpFzS5
55
+ GSyO3kXV13UHFcsaU+jcSFQpZLSCORfSSMWxZNBohVwbIcIOvlBIq4iurnT+
56
+ tu77vYz+s/xn1f7K8iuJunrbSVCHUz8eSU8kJzw1L7mvtYVRd3ReR/xxMO5E
57
+ YDo/bE/15kz/7kCH4/wQTC3dn8E13fknlX5IHHgGAAA=
58
+
59
+ http_version:
60
+ recorded_at: Fri, 29 Jun 2012 20:55:08 GMT
61
+ recorded_with: VCR 2.2.0
@@ -0,0 +1,17 @@
1
+ Feature: Tags API
2
+
3
+ In order to interact with github git data references
4
+ GithubAPI gem
5
+ Should return the expected results depending on passed parameters
6
+
7
+ Background:
8
+ Given I have "Github::GitData::Tags" instance
9
+
10
+ # Scenario: Lists all tags on a repository
11
+ # Given I want to get resource with the following params:
12
+ # | user | repo | sha |
13
+ # | wycats | thor | ffbc56c0c2 |
14
+ # When I make request within a cassette named "git_data/tags/get"
15
+ # Then the response status should be 200
16
+ # And the response type should be JSON
17
+ # And the response should not be empty
@@ -0,0 +1,25 @@
1
+ Feature: Markdown API
2
+
3
+ Background:
4
+ Given I have "Github::Markdown" instance
5
+
6
+ Scenario: Render arbitrary document
7
+
8
+ Given I want to render resource
9
+ And I pass the following request options:
10
+ | text | mode | context |
11
+ | Hello world | gfm | murek/github_api_test |
12
+ When I make request within a cassette named "markdown/render"
13
+ Then the response status should be 200
14
+ And the response type should be HTML
15
+ And the response should not be empty
16
+
17
+ Scenario: Render raw document text/plain
18
+
19
+ Given I want to render_raw resource with the following params:
20
+ | text |
21
+ | Hello cool world |
22
+ When I make request within a cassette named "markdown/render_raw"
23
+ Then the response status should be 200
24
+ And the response type should be HTML
25
+ And the response should not be empty
@@ -13,6 +13,16 @@ Feature: Repositories API
13
13
  And the response type should be JSON
14
14
  And the response should not be empty
15
15
 
16
+ Scenario: Get Branch
17
+
18
+ Given I want branch resource with the following params:
19
+ | user | repo | branch |
20
+ | peter-murach | github | new_dsl |
21
+ When I make request within a cassette named "repos/branch"
22
+ Then the response status should be 200
23
+ And the response type should be JSON
24
+ And the response should not be empty
25
+
16
26
  Scenario: Tags
17
27
 
18
28
  Given I want tags resource with the following params:
@@ -23,7 +23,12 @@ Then /^the response status should be (.*)$/ do |expected_response|
23
23
  end
24
24
 
25
25
  Then /^the response type should be (.*)$/ do |type|
26
- @response.content_type.should =~ /application\/#{type.downcase}/
26
+ case type.downcase
27
+ when 'json'
28
+ @response.content_type.should =~ /application\/json/
29
+ when 'html'
30
+ @response.content_type.should =~ /text\/html/
31
+ end
27
32
  end
28
33
 
29
34
  Then /^the response should have (\d+) items$/ do |size|