github_api 0.7.2 → 0.8.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.
Files changed (74) hide show
  1. data/README.md +6 -5
  2. data/features/{events.feature → activity/events.feature} +8 -8
  3. data/features/{repos → activity}/starring.feature +6 -6
  4. data/features/{repos → activity}/watching.feature +6 -6
  5. data/features/cassettes/{events → activity/events}/issue.yml +0 -0
  6. data/features/cassettes/{events → activity/events}/network.yml +0 -0
  7. data/features/cassettes/{events → activity/events}/org.yml +0 -0
  8. data/features/cassettes/{events → activity/events}/performed.yml +0 -0
  9. data/features/cassettes/{events → activity/events}/public.yml +0 -0
  10. data/features/cassettes/{events → activity/events}/received.yml +0 -0
  11. data/features/cassettes/{events → activity/events}/repo.yml +0 -0
  12. data/features/cassettes/{events → activity/events}/user_org.yml +0 -0
  13. data/features/cassettes/{repos → activity}/starring/list.yml +0 -0
  14. data/features/cassettes/{repos → activity}/starring/star.yml +0 -0
  15. data/features/cassettes/{repos → activity}/starring/starred.yml +0 -0
  16. data/features/cassettes/{repos → activity}/starring/starring.yml +0 -0
  17. data/features/cassettes/{repos → activity}/starring/unstar.yml +0 -0
  18. data/features/cassettes/{repos → activity}/watching/list.yml +0 -0
  19. data/features/cassettes/{repos → activity}/watching/unwatch.yml +0 -0
  20. data/features/cassettes/{repos → activity}/watching/watch.yml +0 -0
  21. data/features/cassettes/{repos → activity}/watching/watched.yml +0 -0
  22. data/features/cassettes/{repos → activity}/watching/watching.yml +0 -0
  23. data/features/github_api.feature +3 -3
  24. data/lib/github_api.rb +1 -1
  25. data/lib/github_api/activity.rb +39 -0
  26. data/lib/github_api/{events.rb → activity/events.rb} +5 -5
  27. data/lib/github_api/activity/notifications.rb +162 -0
  28. data/lib/github_api/{repos → activity}/starring.rb +9 -9
  29. data/lib/github_api/{repos → activity}/watching.rb +9 -9
  30. data/lib/github_api/client.rb +6 -4
  31. data/lib/github_api/repos.rb +2 -14
  32. data/lib/github_api/response.rb +0 -1
  33. data/lib/github_api/version.rb +2 -2
  34. data/spec/fixtures/activity/notifications.json +32 -0
  35. data/spec/fixtures/activity/subscribed.json +8 -0
  36. data/spec/fixtures/activity/threads.json +32 -0
  37. data/spec/github/activity/activity_spec.rb +16 -0
  38. data/spec/github/activity/events/issue_spec.rb +63 -0
  39. data/spec/github/activity/events/network_spec.rb +61 -0
  40. data/spec/github/activity/events/org_spec.rb +60 -0
  41. data/spec/github/activity/events/performed_spec.rb +91 -0
  42. data/spec/github/activity/events/public_spec.rb +55 -0
  43. data/spec/github/activity/events/received_spec.rb +91 -0
  44. data/spec/github/activity/events/repository_spec.rb +65 -0
  45. data/spec/github/activity/events/user_org_spec.rb +63 -0
  46. data/spec/github/activity/notifications/create_spec.rb +44 -0
  47. data/spec/github/activity/notifications/delete_spec.rb +41 -0
  48. data/spec/github/activity/notifications/get_spec.rb +58 -0
  49. data/spec/github/activity/notifications/list_spec.rb +82 -0
  50. data/spec/github/activity/notifications/mark_spec.rb +74 -0
  51. data/spec/github/activity/notifications/subscribed_spec.rb +48 -0
  52. data/spec/github/activity/starring/list_spec.rb +64 -0
  53. data/spec/github/activity/starring/star_spec.rb +36 -0
  54. data/spec/github/activity/starring/starred_spec.rb +53 -0
  55. data/spec/github/activity/starring/starring_spec.rb +38 -0
  56. data/spec/github/activity/starring/unstar_spec.rb +37 -0
  57. data/spec/github/activity/watching/list_spec.rb +59 -0
  58. data/spec/github/activity/watching/unwatch_spec.rb +37 -0
  59. data/spec/github/activity/watching/watch_spec.rb +37 -0
  60. data/spec/github/activity/watching/watched_spec.rb +53 -0
  61. data/spec/github/activity/watching/watching_spec.rb +41 -0
  62. data/spec/github/authorization_spec.rb +2 -2
  63. data/spec/github/issues_spec.rb +1 -1
  64. data/spec/github/repos/comments/delete_spec.rb +2 -0
  65. data/spec/github/repos/delete_spec.rb +1 -1
  66. data/spec/github/repos/get_spec.rb +2 -2
  67. data/spec/github/repos/starring_spec.rb +0 -199
  68. data/spec/github/repos_spec.rb +0 -4
  69. data/spec/github/result_spec.rb +1 -1
  70. metadata +88 -62
  71. data/features/cassettes/git_data/tags/get.yml +0 -54
  72. data/features/git_data/tags.feature +0 -17
  73. data/spec/github/events_spec.rb +0 -491
  74. data/spec/github/repos/watching_spec.rb +0 -203
data/README.md CHANGED
@@ -16,11 +16,12 @@ Supports all the API methods(nearly 200). It's build in a modular way, that is,
16
16
  * Intuitive GitHub API interface navigation.
17
17
  * Modular design allows for working with parts of API.
18
18
  * Fully customizable including advanced middleware stack construction.
19
+ * Its comprehensive, you can request all GitHub API resources.
19
20
  * Requests pagination.
20
21
  * Easy error handling.
21
- * Custom Mime Types specification (TODO)
22
- * Flexible arguments parsing (In progress).
23
- * Full tested with test coverage above 90%.
22
+ * Custom mime types specification (Status: TODO)
23
+ * Flexible arguments parsing (Status: In progress).
24
+ * Fully tested with test coverage above 90% with over 1,200 specs and 500 features.
24
25
 
25
26
  ## Installation
26
27
 
@@ -160,7 +161,7 @@ Github - full API access
160
161
 
161
162
  Github::Gists Github::GitData Github::Repos Github::Search
162
163
  Github::Orgs Github::Issues Github::Authorizations
163
- Github::PullRequests Github::Users Github::Events
164
+ Github::PullRequests Github::Users Github::Activity
164
165
  ```
165
166
 
166
167
  Some parts of GitHub API v3 require you to be autheticated, for instance the following are examples of APIs only for the authenticated user
@@ -367,7 +368,7 @@ users.emails.add 'email1', 'email2', ..., 'emailn' # => Adds emails to the authe
367
368
  If a method returns a collection, you can iterator over it by supplying a block parameter,
368
369
 
369
370
  ```ruby
370
- events = Github::Events.new
371
+ events = Github::Activity::Events.new
371
372
  events.public do |event|
372
373
  puts event.actor.login
373
374
  end
@@ -1,12 +1,12 @@
1
1
  Feature: Events API
2
2
 
3
3
  Background:
4
- Given I have "Github::Events" instance
4
+ Given I have "Github::Activity::Events" instance
5
5
 
6
6
  Scenario: Public
7
7
 
8
8
  Given I want public resources
9
- When I make request within a cassette named "events/public"
9
+ When I make request within a cassette named "activity/events/public"
10
10
  Then the response status should be 200
11
11
  And the response type should be JSON
12
12
  And the response should not be empty
@@ -16,7 +16,7 @@ Feature: Events API
16
16
  Given I want repository resources with the following params:
17
17
  | user | repo |
18
18
  | wycats | thor |
19
- When I make request within a cassette named "events/repo"
19
+ When I make request within a cassette named "activity/events/repo"
20
20
  Then the response status should be 200
21
21
  And the response type should be JSON
22
22
  And the response should not be empty
@@ -26,7 +26,7 @@ Feature: Events API
26
26
  Given I want issue resources with the following params:
27
27
  | user | repo |
28
28
  | wycats | thor |
29
- When I make request within a cassette named "events/issue"
29
+ When I make request within a cassette named "activity/events/issue"
30
30
  Then the response status should be 200
31
31
  And the response type should be JSON
32
32
  And the response should not be empty
@@ -36,7 +36,7 @@ Feature: Events API
36
36
  Given I want network resources with the following params:
37
37
  | user | repo |
38
38
  | wycats | thor |
39
- When I make request within a cassette named "events/network"
39
+ When I make request within a cassette named "activity/events/network"
40
40
  Then the response status should be 200
41
41
  And the response type should be JSON
42
42
  And the response should not be empty
@@ -46,7 +46,7 @@ Feature: Events API
46
46
  Given I want org resources with the following params:
47
47
  | org |
48
48
  | rails |
49
- When I make request within a cassette named "events/org"
49
+ When I make request within a cassette named "activity/events/org"
50
50
  Then the response status should be 200
51
51
  And the response type should be JSON
52
52
  And the response should not be empty
@@ -56,7 +56,7 @@ Feature: Events API
56
56
  Given I want received resources with the following params:
57
57
  | user |
58
58
  | josevalim |
59
- When I make request within a cassette named "events/received"
59
+ When I make request within a cassette named "activity/events/received"
60
60
  Then the response status should be 200
61
61
  And the response type should be JSON
62
62
  And the response should not be empty
@@ -66,7 +66,7 @@ Feature: Events API
66
66
  Given I want performed resources with the following params:
67
67
  | user |
68
68
  | josevalim |
69
- When I make request within a cassette named "events/performed"
69
+ When I make request within a cassette named "activity/events/performed"
70
70
  Then the response status should be 200
71
71
  And the response type should be JSON
72
72
  And the response should not be empty
@@ -1,14 +1,14 @@
1
1
  Feature: Starring API
2
2
 
3
3
  Background:
4
- Given I have "Github::Repos::Starring" instance
4
+ Given I have "Github::Activity::Starring" instance
5
5
 
6
6
  Scenario: List
7
7
 
8
8
  Given I want to list resources with the following params:
9
9
  | user | repo |
10
10
  | peter-murach | github |
11
- When I make request within a cassette named "repos/starring/list"
11
+ When I make request within a cassette named "activity/starring/list"
12
12
  Then the response status should be 200
13
13
  And the response type should be JSON
14
14
  And the response should not be empty
@@ -19,7 +19,7 @@ Feature: Starring API
19
19
  And I pass the following request options:
20
20
  | user |
21
21
  | wycats |
22
- When I make request within a cassette named "repos/starring/starred"
22
+ When I make request within a cassette named "activity/starring/starred"
23
23
  Then the response status should be 200
24
24
  And the response type should be JSON
25
25
  And the response should not be empty
@@ -29,7 +29,7 @@ Feature: Starring API
29
29
  Given I want to starring? resource with the following params:
30
30
  | user | repo |
31
31
  | peter-murach | github |
32
- When I make request within a cassette named "repos/starring/starring"
32
+ When I make request within a cassette named "activity/starring/starring"
33
33
  Then the response should be false
34
34
 
35
35
  Scenario: Star
@@ -37,7 +37,7 @@ Feature: Starring API
37
37
  Given I want to star resource with the following params:
38
38
  | user | repo |
39
39
  | peter-murach | github |
40
- When I make request within a cassette named "repos/starring/star"
40
+ When I make request within a cassette named "activity/starring/star"
41
41
  Then the response status should be 204
42
42
 
43
43
  Scenario: Unstar
@@ -45,6 +45,6 @@ Feature: Starring API
45
45
  Given I want to unstar resource with the following params:
46
46
  | user | repo |
47
47
  | peter-murach | github |
48
- When I make request within a cassette named "repos/starring/unstar"
48
+ When I make request within a cassette named "activity/starring/unstar"
49
49
  Then the response status should be 204
50
50
 
@@ -1,14 +1,14 @@
1
1
  Feature: Watching API
2
2
 
3
3
  Background:
4
- Given I have "Github::Repos::Watching" instance
4
+ Given I have "Github::Activity::Watching" instance
5
5
 
6
6
  Scenario: List
7
7
 
8
8
  Given I want to list resources with the following params:
9
9
  | user | repo |
10
10
  | peter-murach | github |
11
- When I make request within a cassette named "repos/watching/list"
11
+ When I make request within a cassette named "activity/watching/list"
12
12
  Then the response status should be 200
13
13
  And the response type should be JSON
14
14
  And the response should not be empty
@@ -19,7 +19,7 @@ Feature: Watching API
19
19
  And I pass the following request options:
20
20
  | user |
21
21
  | wycats |
22
- When I make request within a cassette named "repos/watching/watched"
22
+ When I make request within a cassette named "activity/watching/watched"
23
23
  Then the response status should be 200
24
24
  And the response type should be JSON
25
25
  And the response should not be empty
@@ -29,7 +29,7 @@ Feature: Watching API
29
29
  Given I want to watching? resource with the following params:
30
30
  | user | repo |
31
31
  | peter-murach | github |
32
- When I make request within a cassette named "repos/watching/watching"
32
+ When I make request within a cassette named "activity/watching/watching"
33
33
  Then the response should be false
34
34
 
35
35
  Scenario: Watch
@@ -37,7 +37,7 @@ Feature: Watching API
37
37
  Given I want to watch resource with the following params:
38
38
  | user | repo |
39
39
  | peter-murach | github |
40
- When I make request within a cassette named "repos/watching/watch"
40
+ When I make request within a cassette named "activity/watching/watch"
41
41
  Then the response status should be 204
42
42
 
43
43
  Scenario: Unwatch
@@ -45,6 +45,6 @@ Feature: Watching API
45
45
  Given I want to unwatch resource with the following params:
46
46
  | user | repo |
47
47
  | peter-murach | github |
48
- When I make request within a cassette named "repos/watching/unwatch"
48
+ When I make request within a cassette named "activity/watching/unwatch"
49
49
  Then the response status should be 204
50
50
 
@@ -49,10 +49,10 @@ Feature: Github API components
49
49
  When I fetch "users"
50
50
  Then I will have access to "Github::Users" API
51
51
 
52
- Scenario: Accessing users API
52
+ Scenario: Accessing activity API
53
53
  Given I have github instance
54
- When I fetch "events"
55
- Then I will have access to "Github::Events" API
54
+ When I fetch "activity"
55
+ Then I will have access to "Github::Activity" API
56
56
 
57
57
  Scenario: Accessing authorizations API
58
58
  Given I have github instance
data/lib/github_api.rb CHANGED
@@ -60,6 +60,7 @@ module Github
60
60
 
61
61
  autoload_all 'github_api',
62
62
  :API => 'api',
63
+ :Activity => 'activity',
63
64
  :ApiFactory => 'api_factory',
64
65
  :Client => 'client',
65
66
  :Repos => 'repos',
@@ -73,7 +74,6 @@ module Github
73
74
  :Orgs => 'orgs',
74
75
  :PullRequests => 'pull_requests',
75
76
  :Users => 'users',
76
- :Events => 'events',
77
77
  :Emojis => 'emojis',
78
78
  :Search => 'search',
79
79
  :Markdown => 'markdown',
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Activity < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/activity',
8
+ :Events => 'events',
9
+ :Notifications => 'notifications',
10
+ :Starring => 'starring',
11
+ :Watching => 'watching'
12
+
13
+ # Create new Activity API
14
+ def initialize(options = {})
15
+ super(options)
16
+ end
17
+
18
+ # Access to Activity::Events API
19
+ def events(options = {})
20
+ @events ||= ApiFactory.new 'Activity::Events', options
21
+ end
22
+
23
+ # Access to Activity::Notifications API
24
+ def notifications
25
+ @notifications ||= ApiFactory.new 'Activity::Notifications'
26
+ end
27
+
28
+ # Access to Activity::Starring API
29
+ def starring
30
+ @starring ||= ApiFactory.new 'Activity::Starring'
31
+ end
32
+
33
+ # Access to Activity::Watching API
34
+ def watching
35
+ @watching ||= ApiFactory.new 'Activity::Watching'
36
+ end
37
+
38
+ end # Activity
39
+ end # Github
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Events < API
4
+ class Activity::Events < API
5
5
 
6
- # Creates new Gists API
6
+ # Creates new Activity::Events API
7
7
  def initialize(options = {})
8
8
  super(options)
9
9
  end
@@ -12,8 +12,8 @@ module Github
12
12
  #
13
13
  # = Examples
14
14
  # github = Github.new
15
- # github.events.public
16
- # github.events.public { |event| ... }
15
+ # github.activity.events.public
16
+ # github.activity.events.public { |event| ... }
17
17
  #
18
18
  def public(params={})
19
19
  normalize! params
@@ -198,5 +198,5 @@ module Github
198
198
  alias :list_user_org_events :user_org
199
199
  alias :list_user_organization_events :user_org
200
200
 
201
- end # Events
201
+ end # Activity::Events
202
202
  end # Github
@@ -0,0 +1,162 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Activity::Notifications < API
5
+
6
+ # Creates new Activity::Notifications API
7
+ def initialize(options = {})
8
+ super(options)
9
+ end
10
+
11
+ # List your notifications
12
+ #
13
+ # List all notifications for the current user, grouped by repository.
14
+ #
15
+ # = Parameters
16
+ # * <tt>:all</tt> - Optional boolean - true to show notifications marked as read.
17
+ # * <tt>:participating</tt> - Optional boolean - true to show only
18
+ # notifications in which the user is directly
19
+ # participating or mentioned.
20
+ # * <tt>:since</tt> - Optional string - filters out any notifications updated
21
+ # before the given time. The time should be passed in as
22
+ # UTC in the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
23
+ # Example: “2012-10-09T23:39:01Z”.
24
+ #
25
+ # = Examples
26
+ # github = Github.new oauth_token: 'token'
27
+ # github.activity.notifications.list
28
+ #
29
+ # List your notifications in a repository
30
+ #
31
+ # = Examples
32
+ # github = Github.new
33
+ # github.activity.notifications.list user: 'user-name', repo: 'repo-name'
34
+ #
35
+ def list(*args)
36
+ params = args.extract_options!
37
+ normalize! params
38
+ filter! %w[ all participating since user repo], params
39
+
40
+ response = if ( (user_name = params.delete("user")) &&
41
+ (repo_name = params.delete("repo")) )
42
+ get_request("/repos/#{user_name}/#{repo_name}/notifications", params)
43
+ else
44
+ get_request("/notifications", params)
45
+ end
46
+ return response unless block_given?
47
+ response.each { |el| yield el }
48
+ end
49
+ alias :all :list
50
+
51
+ # View a single thread
52
+ #
53
+ # = Examples
54
+ # github = Github.new oauth_token: 'token'
55
+ # github.activity.notifications.get 'thread_id'
56
+ # github.activity.notifications.get 'thread_id' { |thread| ... }
57
+ #
58
+ def get(thread_id, params={})
59
+ assert_presence_of thread_id
60
+ normalize! params
61
+ response = get_request("/notifications/threads/#{thread_id}", params)
62
+ return response unless block_given?
63
+ response.each { |el| yield el }
64
+ end
65
+ alias :find :get
66
+
67
+ # Mark as read
68
+ #
69
+ # Marking a notification as “read” removes it from the default view on GitHub.com.
70
+ #
71
+ # = Parameters
72
+ #
73
+ # * <tt>:unread</tt> - boolean - Changes the unread status of the threads.
74
+ # * <tt>:read</tt> - boolean - Inverse of "unread"
75
+ # * <tt>:last_read_at</tt> - optional string time - describes the last point
76
+ # that notifications were checked. Anything updated
77
+ # since this time will not be updated. Default: Now.
78
+ # Expected in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
79
+ # Example: “2012-10-09T23:39:01Z”.
80
+ #
81
+ # = Examples
82
+ # github = Github.new oauth_token: 'token'
83
+ # github.activity.notifications.mark read: true
84
+ #
85
+ # Mark notifications as read in a repository
86
+ #
87
+ # = Examples
88
+ # github.activity.notifications.mark user: 'user-name', repo: 'repo-name',
89
+ # read: true
90
+ #
91
+ # Mark a thread as read
92
+ #
93
+ # = Examples
94
+ # github.activity.notifications.mark thread_id: 'id', read: true
95
+ #
96
+ def mark(*args)
97
+ params = args.extract_options!
98
+ normalize! params
99
+ filter! %w[ unread read last_read_at user repo thread_id], params
100
+
101
+ if ( (user_name = params.delete("user")) &&
102
+ (repo_name = params.delete("repo")) )
103
+
104
+ put_request("/repos/#{user_name}/#{repo_name}/notifications", params)
105
+ elsif (thread_id = params.delete("thread_id"))
106
+ patch_request("/notifications/threads/#{thread_id}", params)
107
+ else
108
+ put_request("/notifications", params)
109
+ end
110
+ end
111
+
112
+ # Check to see if the current user is subscribed to a thread.
113
+ #
114
+ # = Examples
115
+ # github = Github.new oauth_token: 'token'
116
+ # github.activity.notifications.subscribed? 'thread-id'
117
+ #
118
+ def subscribed?(thread_id, params={})
119
+ assert_presence_of thread_id
120
+ normalize! params
121
+ get_request("/notifications/threads/#{thread_id}/subscription", params)
122
+ end
123
+
124
+ # Create a thread subscription
125
+ #
126
+ # This lets you subscribe to a thread, or ignore it. Subscribing to a thread
127
+ # is unnecessary if the user is already subscribed to the repository. Ignoring
128
+ # a thread will mute all future notifications (until you comment or get
129
+ # @mentioned).
130
+ #
131
+ # = Parameters
132
+ # * <tt>:subscribed</tt> - boolean - determines if notifications should be
133
+ # received from this thread.
134
+ # * <tt>:ignored</tt> - boolean - deterimines if all notifications should be
135
+ # blocked from this thread.
136
+ # = Examples
137
+ # github = Github.new oauth_token: 'token'
138
+ # github.activity.notifications.create 'thread-id',
139
+ # 'subscribed': true
140
+ # 'ignored': false
141
+ #
142
+ def create(thread_id, params={})
143
+ assert_presence_of thread_id
144
+ normalize! params
145
+ put_request("/notifications/threads/#{thread_id}/subscription", params)
146
+ end
147
+
148
+ # Delete a thread subscription
149
+ #
150
+ # = Examples
151
+ # github = Github.new oauth_token: 'token'
152
+ # github.activity.notifications.delete 'thread_id'
153
+ #
154
+ def delete(thread_id, params={})
155
+ assert_presence_of thread_id
156
+ normalize! params
157
+ delete_request("/notifications/threads/#{thread_id}/subscription", params)
158
+ end
159
+ alias :remove :delete
160
+
161
+ end # Activity::Notifications
162
+ end # Github