PageRenderTime 107ms CodeModel.GetById 84ms app.highlight 11ms RepoModel.GetById 3ms app.codeStats 0ms

/lib/octokit/client/events.rb

http://github.com/pengwynn/octokit
Ruby | 152 lines | 44 code | 13 blank | 95 comment | 0 complexity | ae600a11c54fedecb8103289edfeef0d MD5 | raw file
  1module Octokit
  2  class Client
  3
  4    # Method for the Events API
  5    #
  6    # @see https://developer.github.com/v3/activity/events/
  7    # @see https://developer.github.com/v3/issues/events/
  8    module Events
  9
 10      # List all public events for GitHub
 11      #
 12      # @return [Array<Sawyer::Resource>] A list of all public events from GitHub
 13      # @see https://developer.github.com/v3/activity/events/#list-public-events
 14      # @example List all pubilc events
 15      #   Octokit.public_events
 16      def public_events(options = {})
 17        paginate "events", options
 18      end
 19
 20      # List all user events
 21      #
 22      # @param user [Integer, String] GitHub user login or id.
 23      # @return [Array<Sawyer::Resource>] A list of all user events
 24      # @see https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
 25      # @example List all user events
 26      #   Octokit.user_events("sferik")
 27      def user_events(user, options = {})
 28        paginate "#{User.path user}/events", options
 29      end
 30
 31      # List public user events
 32      #
 33      # @param user [Integer, String] GitHub user login or id
 34      # @return [Array<Sawyer::Resource>] A list of public user events
 35      # @see https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user
 36      # @example List public user events
 37      #   Octokit.user_events("sferik")
 38      def user_public_events(user, options = {})
 39        paginate "#{User.path user}/events/public", options
 40      end
 41
 42      # List events that a user has received
 43      #
 44      # @param user [Integer, String] GitHub user login or id
 45      # @return [Array<Sawyer::Resource>] A list of all user received events
 46      # @see https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
 47      # @example List all user received events
 48      #   Octokit.received_events("sferik")
 49      def received_events(user, options = {})
 50        paginate "#{User.path user}/received_events", options
 51      end
 52
 53      # List public events a user has received
 54      #
 55      # @param user [Integer, String] GitHub user login or id
 56      # @return [Array<Sawyer::Resource>] A list of public user received events
 57      # @see https://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received
 58      # @example List public user received events
 59      #   Octokit.received_public_events("sferik")
 60      def received_public_events(user, options = {})
 61        paginate "#{User.path user}/received_events/public", options
 62      end
 63
 64      # List events for a repository
 65      #
 66      # @param repo [Integer, String, Repository, Hash] A GitHub repository
 67      # @return [Array<Sawyer::Resource>] A list of events for a repository
 68      # @see https://developer.github.com/v3/activity/events/#list-repository-events
 69      # @example List events for a repository
 70      #   Octokit.repository_events("sferik/rails_admin")
 71      def repository_events(repo, options = {})
 72        paginate "#{Repository.path repo}/events", options
 73      end
 74
 75      # List public events for a repository's network
 76      #
 77      # @param repo [String, Repository, Hash] A GitHub repository
 78      # @return [Array<Sawyer::Resource>] A list of events for a repository's network
 79      # @see https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
 80      # @example List events for a repository's network
 81      #   Octokit.repository_network_events("sferik/rails_admin")
 82      def repository_network_events(repo, options = {})
 83        paginate "networks/#{Repository.new(repo)}/events", options
 84      end
 85
 86      # List all events for an organization
 87      #
 88      # Requires authenticated client.
 89      #
 90      # @param org [String] Organization GitHub handle
 91      # @return [Array<Sawyer::Resource>] List of all events from a GitHub organization
 92      # @see https://developer.github.com/v3/activity/events/#list-events-for-an-organization
 93      # @example List events for the lostisland organization
 94      #   @client.organization_events("lostisland")
 95      def organization_events(org, options = {})
 96        paginate "users/#{login}/events/orgs/#{org}", options
 97      end
 98
 99      # List an organization's public events
100      #
101      # @param org [String, Integer] Organization GitHub login or id.
102      # @return [Array<Sawyer::Resource>] List of public events from a GitHub organization
103      # @see https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
104      # @example List public events for GitHub
105      #   Octokit.organization_public_events("GitHub")
106      def organization_public_events(org, options = {})
107        paginate "#{Organization.path org}/events", options
108      end
109
110      # Get all Issue Events for a given Repository
111      #
112      # @param repo [Integer, String, Repository, Hash] A GitHub repository
113      #
114      # @return [Array<Sawyer::Resource>] Array of all Issue Events for this Repository
115      # @see https://developer.github.com/v3/issues/events/#list-events-for-a-repository
116      # @see https://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
117      # @example Get all Issue Events for Octokit
118      #   Octokit.repository_issue_events("octokit/octokit.rb")
119      def repository_issue_events(repo, options = {})
120        paginate "#{Repository.path repo}/issues/events", options
121      end
122      alias :repo_issue_events :repository_issue_events
123
124      # List events for an Issue
125      #
126      # @param repo [Integer, String, Repository, Hash] A GitHub repository
127      # @param number [Integer] Issue number
128      #
129      # @return [Array<Sawyer::Resource>] Array of events for that issue
130      # @see https://developer.github.com/v3/issues/events/#list-events-for-an-issue
131      # @example List all issues events for issue #38 on octokit/octokit.rb
132      #   Octokit.issue_events("octokit/octokit.rb", 38)
133      def issue_events(repo, number, options = {})
134        options = ensure_api_media_type(:project_card_events, options)
135        paginate "#{Repository.path repo}/issues/#{number}/events", options
136      end
137
138      # Get information on a single Issue Event
139      #
140      # @param repo [Integer, String, Repository, Hash] A GitHub repository
141      # @param number [Integer] Event number
142      #
143      # @return [Sawyer::Resource] A single Event for an Issue
144      # @see https://developer.github.com/v3/issues/events/#get-a-single-event
145      # @example Get Event information for ID 3094334 (a pull request was closed)
146      #   Octokit.issue_event("octokit/octokit.rb", 3094334)
147      def issue_event(repo, number, options = {})
148        paginate "#{Repository.path repo}/issues/events/#{number}", options
149      end
150    end
151  end
152end