# Generated by API Builder - https://www.apibuilder.io # Service version: 0.5.7 # User agent: apibuilder app.apibuilder.io/flow/github/0.5.7/ruby_client require 'cgi' require 'net/http' require 'net/https' require 'uri' require 'base64' require 'date' require 'rubygems' require 'json' require 'bigdecimal' # See https://developer.github.com/v3/ module Io module Flow module Github module V0 class Client module Constants BASE_URL = 'https://api.github.com' unless defined?(Constants::BASE_URL) NAMESPACE = 'io.flow.github.v0' unless defined?(Constants::NAMESPACE) USER_AGENT = 'apibuilder app.apibuilder.io/flow/github/0.5.7/ruby_client' unless defined?(Constants::USER_AGENT) VERSION = '0.5.7' unless defined?(Constants::VERSION) VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR) end attr_reader :url def initialize(url, opts={}) @url = HttpClient::Preconditions.assert_class('url', url, String) @base_url = URI(url) @authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization) @default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash) @http_handler = opts.delete(:http_handler) || HttpClient::DefaultHttpHandler.new HttpClient::Preconditions.assert_empty_opts(opts) HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url) end # Creates an instance of the client using the base url specified in the API spec. def Client.at_base_url(opts={}) Client.new(Constants::BASE_URL, opts) end def request(path=nil) HttpClient::Preconditions.assert_class_or_nil('path', path, String) request = HttpClient::Request.new(@http_handler, @base_url, path.to_s).with_header('User-Agent', Constants::USER_AGENT).with_header('X-Apidoc-Version', Constants::VERSION).with_header('X-Apidoc-Version-Major', Constants::VERSION_MAJOR) @default_headers.each do |key, value| request = request.with_header(key, value) end if @authorization request = request.with_auth(@authorization) end request end def blobs @blobs ||= ::Io::Flow::Github::V0::Clients::Blobs.new(self) end def commits @commits ||= ::Io::Flow::Github::V0::Clients::Commits.new(self) end def contents @contents ||= ::Io::Flow::Github::V0::Clients::Contents.new(self) end def hooks @hooks ||= ::Io::Flow::Github::V0::Clients::Hooks.new(self) end def pull_requests @pull_requests ||= ::Io::Flow::Github::V0::Clients::PullRequests.new(self) end def refs @refs ||= ::Io::Flow::Github::V0::Clients::Refs.new(self) end def repositories @repositories ||= ::Io::Flow::Github::V0::Clients::Repositories.new(self) end def tags @tags ||= ::Io::Flow::Github::V0::Clients::Tags.new(self) end def trees @trees ||= ::Io::Flow::Github::V0::Clients::Trees.new(self) end def users @users ||= ::Io::Flow::Github::V0::Clients::Users.new(self) end def user_emails @user_emails ||= ::Io::Flow::Github::V0::Clients::UserEmails.new(self) end end module Clients class Blobs def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_by_sha(owner, repo, sha) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('sha', sha, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/blobs/#{CGI.escape(sha)}").get ::Io::Flow::Github::V0::Models::Blob.new(r) end def post(owner, repo, blob_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = blob_form; x.is_a?(::Io::Flow::Github::V0::Models::BlobForm) ? x : ::Io::Flow::Github::V0::Models::BlobForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/blobs").with_json(blob_form.to_json).post ::Io::Flow::Github::V0::Models::BlobCreated.new(r) end end class Commits def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_by_sha(owner, repo, sha) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('sha', sha, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/commits/#{CGI.escape(sha)}").get ::Io::Flow::Github::V0::Models::Commit.new(r) end def post(owner, repo, commit_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = commit_form; x.is_a?(::Io::Flow::Github::V0::Models::CommitForm) ? x : ::Io::Flow::Github::V0::Models::CommitForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/commits").with_json(commit_form.to_json).post ::Io::Flow::Github::V0::Models::CommitResponse.new(r) end end class Contents def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_readme(owner, repo, incoming={}) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :ref => HttpClient::Preconditions.assert_class('ref', (x = opts.delete(:ref); x.nil? ? "main" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/readme").with_query(query).get ::Io::Flow::Github::V0::Models::Contents.new(r) end def get_contents_by_path(owner, repo, path, incoming={}) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('path', path, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :ref => HttpClient::Preconditions.assert_class('ref', (x = opts.delete(:ref); x.nil? ? "main" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/contents/#{CGI.escape(path)}").with_query(query).get ::Io::Flow::Github::V0::Models::Contents.new(r) end end class Hooks def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get(owner, repo) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/hooks").get r.map { |x| ::Io::Flow::Github::V0::Models::Hook.new(x) } end def get_by_id(owner, repo, id) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('id', id, Integer) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/hooks/#{id}").get ::Io::Flow::Github::V0::Models::Hook.new(r) end def post(owner, repo, hook_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = hook_form; x.is_a?(::Io::Flow::Github::V0::Models::HookForm) ? x : ::Io::Flow::Github::V0::Models::HookForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/hooks").with_json(hook_form.to_json).post ::Io::Flow::Github::V0::Models::Hook.new(r) end def delete_by_id(owner, repo, id) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('id', id, Integer) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/hooks/#{id}").delete nil end end class PullRequests def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def post(owner, repo, pull_request_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = pull_request_form; x.is_a?(::Io::Flow::Github::V0::Models::PullRequestForm) ? x : ::Io::Flow::Github::V0::Models::PullRequestForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/pulls").with_json(pull_request_form.to_json).post ::Io::Flow::Github::V0::Models::PullRequest.new(r) end def get(owner, repo, incoming={}) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer) }.delete_if { |k, v| v.nil? } r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/pulls").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::PullRequest.new(x) } end end class Refs def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get(owner, repo) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/refs").get r.map { |x| ::Io::Flow::Github::V0::Models::Ref.new(x) } end def get_by_ref(owner, repo, ref) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('ref', ref, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/refs/#{CGI.escape(ref)}").get ::Io::Flow::Github::V0::Models::Ref.new(r) end def post(owner, repo, ref_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = ref_form; x.is_a?(::Io::Flow::Github::V0::Models::RefForm) ? x : ::Io::Flow::Github::V0::Models::RefForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/refs").with_json(ref_form.to_json).post ::Io::Flow::Github::V0::Models::Ref.new(r) end def put_by_ref(owner, repo, ref, ref_update_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('ref', ref, String) (x = ref_update_form; x.is_a?(::Io::Flow::Github::V0::Models::RefUpdateForm) ? x : ::Io::Flow::Github::V0::Models::RefUpdateForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/refs/#{CGI.escape(ref)}").with_json(ref_update_form.to_json).put ::Io::Flow::Github::V0::Models::Ref.new(r) end end class Repositories def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_user_and_repos(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer), :visibility => (x = (x = opts.delete(:visibility); x.nil? ? "all" : x); x.is_a?(::Io::Flow::Github::V0::Models::Visibility) ? x : ::Io::Flow::Github::V0::Models::Visibility.apply(x)).value, :affiliation => (x = opts.delete(:affiliation); x.nil? ? nil : HttpClient::Preconditions.assert_class('affiliation', x, String)), :type => (x = opts.delete(:type); x.nil? ? nil : HttpClient::Preconditions.assert_class('type', x, String)), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "full_name" : x), String), :direction => HttpClient::Preconditions.assert_class('direction', (x = opts.delete(:direction); x.nil? ? "asc" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/user/repos").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::Repository.new(x) } end # List public repositories for the specified user. def get_users_and_repos_by_username(username, incoming={}) HttpClient::Preconditions.assert_class('username', username, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer), :type => HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "owner" : x), String), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "full_name" : x), String), :direction => HttpClient::Preconditions.assert_class('direction', (x = opts.delete(:direction); x.nil? ? "asc" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/users/#{CGI.escape(username)}/repos").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::Repository.new(x) } end # List repositories for the specified org. def get_orgs_and_repos_by_org(org, incoming={}) HttpClient::Preconditions.assert_class('org', org, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer), :type => HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "all" : x), String), :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "full_name" : x), String), :direction => HttpClient::Preconditions.assert_class('direction', (x = opts.delete(:direction); x.nil? ? "asc" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/orgs/#{CGI.escape(org)}/repos").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::Repository.new(x) } end end class Tags def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_tags(owner, repo, incoming={}) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer), :per_page => HttpClient::Preconditions.assert_class('per_page', (x = opts.delete(:per_page); x.nil? ? 30 : x), Integer) }.delete_if { |k, v| v.nil? } r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/tags").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::TagSummary.new(x) } end def get_tags_by_sha(owner, repo, sha) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) HttpClient::Preconditions.assert_class('sha', sha, String) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/tags/#{CGI.escape(sha)}").get ::Io::Flow::Github::V0::Models::Tag.new(r) end def post_git_and_tags(owner, repo, tag_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = tag_form; x.is_a?(::Io::Flow::Github::V0::Models::TagForm) ? x : ::Io::Flow::Github::V0::Models::TagForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/tags").with_json(tag_form.to_json).post ::Io::Flow::Github::V0::Models::Tag.new(r) end end class Trees def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def post(owner, repo, create_tree_form) HttpClient::Preconditions.assert_class('owner', owner, String) HttpClient::Preconditions.assert_class('repo', repo, String) (x = create_tree_form; x.is_a?(::Io::Flow::Github::V0::Models::CreateTreeForm) ? x : ::Io::Flow::Github::V0::Models::CreateTreeForm.new(x)) r = @client.request("/repos/#{CGI.escape(owner)}/#{CGI.escape(repo)}/git/trees").with_json(create_tree_form.to_json).post ::Io::Flow::Github::V0::Models::CreateTreeResponse.new(r) end end class Users def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get_user r = @client.request("/user").get ::Io::Flow::Github::V0::Models::User.new(r) end def get_user_and_orgs(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :page => HttpClient::Preconditions.assert_class('page', (x = opts.delete(:page); x.nil? ? 1 : x), Integer), :per_page => (x = opts.delete(:per_page); x.nil? ? nil : HttpClient::Preconditions.assert_class('per_page', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/user/orgs").with_query(query).get r.map { |x| ::Io::Flow::Github::V0::Models::UserOrg.new(x) } end end class UserEmails def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::Github::V0::Client) end def get r = @client.request("/user/emails").get r.map { |x| ::Io::Flow::Github::V0::Models::UserEmail.new(x) } end end end module Models class ContentsType attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of ContentsType for this value, creating a new instance for an unknown value def ContentsType.apply(value) if value.instance_of?(ContentsType) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || ContentsType.new(value)) end end # Returns the instance of ContentsType for this value, or nil if not found def ContentsType.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) ContentsType.ALL.find { |v| v.value == value } end def ContentsType.ALL @@all ||= [ContentsType.file, ContentsType.dir, ContentsType.symlink, ContentsType.submodule] end def ContentsType.file @@_file ||= ContentsType.new('file') end def ContentsType.dir @@_dir ||= ContentsType.new('dir') end def ContentsType.symlink @@_symlink ||= ContentsType.new('symlink') end def ContentsType.submodule @@_submodule ||= ContentsType.new('submodule') end def to_hash value end end class Encoding attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of Encoding for this value, creating a new instance for an unknown value def Encoding.apply(value) if value.instance_of?(Encoding) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || Encoding.new(value)) end end # Returns the instance of Encoding for this value, or nil if not found def Encoding.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) Encoding.ALL.find { |v| v.value == value } end def Encoding.ALL @@all ||= [Encoding.base64, Encoding.utf_8] end def Encoding.base64 @@_base64 ||= Encoding.new('base64') end def Encoding.utf_8 @@_utf_8 ||= Encoding.new('utf-8') end def to_hash value end end class HookEvent attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of HookEvent for this value, creating a new instance for an unknown value def HookEvent.apply(value) if value.instance_of?(HookEvent) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || HookEvent.new(value)) end end # Returns the instance of HookEvent for this value, or nil if not found def HookEvent.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) HookEvent.ALL.find { |v| v.value == value } end def HookEvent.ALL @@all ||= [HookEvent.push, HookEvent.pull_request] end def HookEvent.push @@_push ||= HookEvent.new('push') end def HookEvent.pull_request @@_pull_request ||= HookEvent.new('pull_request') end def to_hash value end end class NodeType attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of NodeType for this value, creating a new instance for an unknown value def NodeType.apply(value) if value.instance_of?(NodeType) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || NodeType.new(value)) end end # Returns the instance of NodeType for this value, or nil if not found def NodeType.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) NodeType.ALL.find { |v| v.value == value } end def NodeType.ALL @@all ||= [NodeType.blob, NodeType.tree, NodeType.commit] end def NodeType.blob @@_blob ||= NodeType.new('blob') end def NodeType.tree @@_tree ||= NodeType.new('tree') end def NodeType.commit @@_commit ||= NodeType.new('commit') end def to_hash value end end class OwnerType attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of OwnerType for this value, creating a new instance for an unknown value def OwnerType.apply(value) if value.instance_of?(OwnerType) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || OwnerType.new(value)) end end # Returns the instance of OwnerType for this value, or nil if not found def OwnerType.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) OwnerType.ALL.find { |v| v.value == value } end def OwnerType.ALL @@all ||= [OwnerType.user] end def OwnerType.user @@_user ||= OwnerType.new('User') end def to_hash value end end class Visibility attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of Visibility for this value, creating a new instance for an unknown value def Visibility.apply(value) if value.instance_of?(Visibility) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || Visibility.new(value)) end end # Returns the instance of Visibility for this value, or nil if not found def Visibility.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) Visibility.ALL.find { |v| v.value == value } end def Visibility.ALL @@all ||= [Visibility.all, Visibility.public, Visibility.private] end def Visibility.all @@_all ||= Visibility.new('all') end def Visibility.public @@_public ||= Visibility.new('public') end def Visibility.private @@_private ||= Visibility.new('private') end def to_hash value end end class Blob attr_reader :content, :encoding, :url, :sha, :size def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:content, :encoding, :url, :sha, :size], 'Blob') @content = HttpClient::Preconditions.assert_class('content', opts.delete(:content), String) @encoding = (x = opts.delete(:encoding); x.is_a?(::Io::Flow::Github::V0::Models::Encoding) ? x : ::Io::Flow::Github::V0::Models::Encoding.apply(x)) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @size = HttpClient::Preconditions.assert_class('size', opts.delete(:size), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Blob.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :content => content, :encoding => encoding.value, :url => url, :sha => sha, :size => size } end end class BlobCreated attr_reader :url, :sha def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:url, :sha], 'BlobCreated') @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) BlobCreated.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :url => url, :sha => sha } end end class BlobForm attr_reader :content, :encoding def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:content], 'BlobForm') @content = HttpClient::Preconditions.assert_class('content', opts.delete(:content), String) @encoding = (x = (x = opts.delete(:encoding); x.nil? ? "utf-8" : x); x.is_a?(::Io::Flow::Github::V0::Models::Encoding) ? x : ::Io::Flow::Github::V0::Models::Encoding.apply(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) BlobForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :content => content, :encoding => encoding.value } end end class Commit attr_reader :sha, :url, :html_url, :author, :committer, :tree, :message, :parents def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha, :url, :html_url, :author, :committer, :tree, :message, :parents], 'Commit') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @html_url = HttpClient::Preconditions.assert_class('html_url', opts.delete(:html_url), String) @author = (x = opts.delete(:author); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) @committer = (x = opts.delete(:committer); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) @tree = (x = opts.delete(:tree); x.is_a?(::Io::Flow::Github::V0::Models::TreeSummary) ? x : ::Io::Flow::Github::V0::Models::TreeSummary.new(x)) @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @parents = HttpClient::Preconditions.assert_class('parents', opts.delete(:parents), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::CommitSummary) ? x : ::Io::Flow::Github::V0::Models::CommitSummary.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) Commit.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha, :url => url, :html_url => html_url, :author => author.to_hash, :committer => committer.to_hash, :tree => tree.to_hash, :message => message, :parents => parents.map { |o| o.to_hash } } end end class CommitForm attr_reader :message, :tree, :parents, :author, :committer def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:message, :tree, :parents, :author, :committer], 'CommitForm') @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @tree = HttpClient::Preconditions.assert_class('tree', opts.delete(:tree), String) @parents = HttpClient::Preconditions.assert_class('parents', opts.delete(:parents), Array).map { |v| HttpClient::Preconditions.assert_class('parents', v, String) } @author = (x = opts.delete(:author); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) @committer = (x = opts.delete(:committer); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) CommitForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :message => message, :tree => tree, :parents => parents, :author => author.to_hash, :committer => committer.to_hash } end end class CommitResponse attr_reader :sha, :url, :author, :committer, :message, :tree, :parents def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha, :url, :author, :committer, :message, :tree, :parents], 'CommitResponse') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @author = (x = opts.delete(:author); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) @committer = (x = opts.delete(:committer); x.is_a?(::Io::Flow::Github::V0::Models::Person) ? x : ::Io::Flow::Github::V0::Models::Person.new(x)) @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @tree = (x = opts.delete(:tree); x.is_a?(::Io::Flow::Github::V0::Models::TreeSummary) ? x : ::Io::Flow::Github::V0::Models::TreeSummary.new(x)) @parents = HttpClient::Preconditions.assert_class('parents', opts.delete(:parents), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::TreeSummary) ? x : ::Io::Flow::Github::V0::Models::TreeSummary.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) CommitResponse.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha, :url => url, :author => author.to_hash, :committer => committer.to_hash, :message => message, :tree => tree.to_hash, :parents => parents.map { |o| o.to_hash } } end end class CommitSummary attr_reader :sha, :url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha, :url], 'CommitSummary') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) CommitSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha, :url => url } end end class Contents attr_reader :type, :encoding, :size, :name, :path, :content, :sha, :url, :git_url, :html_url, :download_url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:type, :encoding, :size, :name, :path, :sha, :url, :git_url, :html_url, :download_url], 'Contents') @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::ContentsType) ? x : ::Io::Flow::Github::V0::Models::ContentsType.apply(x)) @encoding = (x = opts.delete(:encoding); x.is_a?(::Io::Flow::Github::V0::Models::Encoding) ? x : ::Io::Flow::Github::V0::Models::Encoding.apply(x)) @size = HttpClient::Preconditions.assert_class('size', opts.delete(:size), Integer) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @path = HttpClient::Preconditions.assert_class('path', opts.delete(:path), String) @content = (x = opts.delete(:content); x.nil? ? nil : HttpClient::Preconditions.assert_class('content', x, String)) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @git_url = HttpClient::Preconditions.assert_class('git_url', opts.delete(:git_url), String) @html_url = HttpClient::Preconditions.assert_class('html_url', opts.delete(:html_url), String) @download_url = HttpClient::Preconditions.assert_class('download_url', opts.delete(:download_url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Contents.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :type => type.value, :encoding => encoding.value, :size => size, :name => name, :path => path, :content => content, :sha => sha, :url => url, :git_url => git_url, :html_url => html_url, :download_url => download_url } end end class CreateTreeForm attr_reader :base_tree, :tree def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:base_tree, :tree], 'CreateTreeForm') @base_tree = HttpClient::Preconditions.assert_class('base_tree', opts.delete(:base_tree), String) @tree = HttpClient::Preconditions.assert_class('tree', opts.delete(:tree), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::TreeForm) ? x : ::Io::Flow::Github::V0::Models::TreeForm.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) CreateTreeForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :base_tree => base_tree, :tree => tree.map { |o| o.to_hash } } end end class CreateTreeResponse attr_reader :sha, :url, :tree_result def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha, :url, :tree_result], 'CreateTreeResponse') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @tree_result = (x = opts.delete(:tree_result); x.is_a?(::Io::Flow::Github::V0::Models::Tree) ? x : ::Io::Flow::Github::V0::Models::Tree.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) CreateTreeResponse.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha, :url => url, :tree_result => tree_result.to_hash } end end class Error attr_reader :resource, :field, :code def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:resource, :field, :code], 'Error') @resource = HttpClient::Preconditions.assert_class('resource', opts.delete(:resource), String) @field = HttpClient::Preconditions.assert_class('field', opts.delete(:field), String) @code = HttpClient::Preconditions.assert_class('code', opts.delete(:code), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Error.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :resource => resource, :field => field, :code => code } end end class GithubObject attr_reader :type, :sha, :url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:type, :sha, :url], 'GithubObject') @type = HttpClient::Preconditions.assert_class('type', opts.delete(:type), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) GithubObject.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :type => type, :sha => sha, :url => url } end end # See https://developer.github.com/v3/repos/hooks/#create-a-hook class Hook attr_reader :id, :url, :test_url, :ping_url, :name, :events, :active, :config, :updated_at, :created_at def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :url, :test_url, :ping_url, :name, :events, :active, :config, :updated_at, :created_at], 'Hook') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @test_url = HttpClient::Preconditions.assert_class('test_url', opts.delete(:test_url), String) @ping_url = HttpClient::Preconditions.assert_class('ping_url', opts.delete(:ping_url), String) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @events = HttpClient::Preconditions.assert_class('events', opts.delete(:events), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::HookEvent) ? x : ::Io::Flow::Github::V0::Models::HookEvent.apply(x)) } @active = HttpClient::Preconditions.assert_boolean('active', opts.delete(:active)) @config = (x = opts.delete(:config); x.is_a?(::Io::Flow::Github::V0::Models::HookConfig) ? x : ::Io::Flow::Github::V0::Models::HookConfig.new(x)) @updated_at = HttpClient::Preconditions.assert_class('updated_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:updated_at)), DateTime) @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Hook.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :id => id, :url => url, :test_url => test_url, :ping_url => ping_url, :name => name, :events => events.map { |o| o.value }, :active => active, :config => config.to_hash, :updated_at => updated_at, :created_at => created_at } end end class HookConfig attr_reader :url, :content_type def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @url = (x = opts.delete(:url); x.nil? ? nil : HttpClient::Preconditions.assert_class('url', x, String)) @content_type = (x = opts.delete(:content_type); x.nil? ? nil : HttpClient::Preconditions.assert_class('content_type', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) HookConfig.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :url => url, :content_type => content_type } end end class HookForm attr_reader :name, :config, :events, :active def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :config, :events, :active], 'HookForm') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @config = (x = opts.delete(:config); x.is_a?(::Io::Flow::Github::V0::Models::HookConfig) ? x : ::Io::Flow::Github::V0::Models::HookConfig.new(x)) @events = HttpClient::Preconditions.assert_class('events', opts.delete(:events), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::HookEvent) ? x : ::Io::Flow::Github::V0::Models::HookEvent.apply(x)) } @active = HttpClient::Preconditions.assert_boolean('active', opts.delete(:active)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) HookForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :config => config.to_hash, :events => events.map { |o| o.value }, :active => active } end end class Node attr_reader :path, :mode, :type, :size, :sha, :url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:path, :mode, :type, :size, :sha, :url], 'Node') @path = HttpClient::Preconditions.assert_class('path', opts.delete(:path), String) @mode = HttpClient::Preconditions.assert_class('mode', opts.delete(:mode), String) @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::NodeType) ? x : ::Io::Flow::Github::V0::Models::NodeType.apply(x)) @size = HttpClient::Preconditions.assert_class('size', opts.delete(:size), Integer) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Node.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :path => path, :mode => mode, :type => type.value, :size => size, :sha => sha, :url => url } end end class NodeForm attr_reader :path, :mode, :type, :sha def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:path, :mode, :type, :sha], 'NodeForm') @path = HttpClient::Preconditions.assert_class('path', opts.delete(:path), String) @mode = HttpClient::Preconditions.assert_class('mode', opts.delete(:mode), String) @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::NodeType) ? x : ::Io::Flow::Github::V0::Models::NodeType.apply(x)) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NodeForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :path => path, :mode => mode, :type => type.value, :sha => sha } end end class Person attr_reader :name, :email, :date def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :email, :date], 'Person') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @email = HttpClient::Preconditions.assert_class('email', opts.delete(:email), String) @date = HttpClient::Preconditions.assert_class('date', HttpClient::Helper.to_date_time_iso8601(opts.delete(:date)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Person.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :email => email, :date => date } end end class PullRequest attr_reader :id, :url, :number, :html_url, :head def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :url, :number, :html_url, :head], 'PullRequest') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), Integer) @html_url = HttpClient::Preconditions.assert_class('html_url', opts.delete(:html_url), String) @head = (x = opts.delete(:head); x.is_a?(::Io::Flow::Github::V0::Models::PullRequestHead) ? x : ::Io::Flow::Github::V0::Models::PullRequestHead.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PullRequest.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :id => id, :url => url, :number => number, :html_url => html_url, :head => head.to_hash } end end class PullRequestForm attr_reader :title, :head, :base, :body def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:title, :head, :base], 'PullRequestForm') @title = HttpClient::Preconditions.assert_class('title', opts.delete(:title), String) @head = HttpClient::Preconditions.assert_class('head', opts.delete(:head), String) @base = HttpClient::Preconditions.assert_class('base', opts.delete(:base), String) @body = (x = opts.delete(:body); x.nil? ? nil : HttpClient::Preconditions.assert_class('body', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PullRequestForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :title => title, :head => head, :base => base, :body => body } end end class PullRequestHead attr_reader :ref def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:ref], 'PullRequestHead') @ref = HttpClient::Preconditions.assert_class('ref', opts.delete(:ref), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PullRequestHead.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :ref => ref } end end class Ref attr_reader :ref, :url, :object def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:ref, :url, :object], 'Ref') @ref = HttpClient::Preconditions.assert_class('ref', opts.delete(:ref), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @object = (x = opts.delete(:object); x.is_a?(::Io::Flow::Github::V0::Models::GithubObject) ? x : ::Io::Flow::Github::V0::Models::GithubObject.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Ref.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :ref => ref, :url => url, :object => object.to_hash } end end class RefForm attr_reader :ref, :sha def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:ref, :sha], 'RefForm') @ref = HttpClient::Preconditions.assert_class('ref', opts.delete(:ref), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) RefForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :ref => ref, :sha => sha } end end class RefUpdateForm attr_reader :sha def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha], 'RefUpdateForm') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) RefUpdateForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha } end end class Repository attr_reader :id, :owner, :name, :full_name, :private, :description, :url, :html_url, :default_branch def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :owner, :name, :full_name, :private, :url, :html_url, :default_branch], 'Repository') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @owner = (x = opts.delete(:owner); x.is_a?(::Io::Flow::Github::V0::Models::User) ? x : ::Io::Flow::Github::V0::Models::User.new(x)) @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @full_name = HttpClient::Preconditions.assert_class('full_name', opts.delete(:full_name), String) @private = HttpClient::Preconditions.assert_boolean('private', opts.delete(:private)) @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String)) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @html_url = HttpClient::Preconditions.assert_class('html_url', opts.delete(:html_url), String) @default_branch = HttpClient::Preconditions.assert_class('default_branch', opts.delete(:default_branch), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Repository.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :id => id, :owner => owner.to_hash, :name => name, :full_name => full_name, :private => private, :description => description, :url => url, :html_url => html_url, :default_branch => default_branch } end end class Tag attr_reader :tag, :sha, :url, :message, :tagger, :object def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:tag, :sha, :url, :message, :tagger, :object], 'Tag') @tag = HttpClient::Preconditions.assert_class('tag', opts.delete(:tag), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @tagger = (x = opts.delete(:tagger); x.is_a?(::Io::Flow::Github::V0::Models::Tagger) ? x : ::Io::Flow::Github::V0::Models::Tagger.new(x)) @object = (x = opts.delete(:object); x.is_a?(::Io::Flow::Github::V0::Models::GithubObject) ? x : ::Io::Flow::Github::V0::Models::GithubObject.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Tag.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :tag => tag, :sha => sha, :url => url, :message => message, :tagger => tagger.to_hash, :object => object.to_hash } end end class TagForm attr_reader :tag, :message, :object, :type, :tagger def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:tag, :message, :object, :tagger], 'TagForm') @tag = HttpClient::Preconditions.assert_class('tag', opts.delete(:tag), String) @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @object = HttpClient::Preconditions.assert_class('object', opts.delete(:object), String) @type = HttpClient::Preconditions.assert_class('type', (x = opts.delete(:type); x.nil? ? "commit" : x), String) @tagger = (x = opts.delete(:tagger); x.is_a?(::Io::Flow::Github::V0::Models::Tagger) ? x : ::Io::Flow::Github::V0::Models::Tagger.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TagForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :tag => tag, :message => message, :object => object, :type => type, :tagger => tagger.to_hash } end end class TagSummary attr_reader :name, :commit def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :commit], 'TagSummary') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @commit = (x = opts.delete(:commit); x.is_a?(::Io::Flow::Github::V0::Models::CommitSummary) ? x : ::Io::Flow::Github::V0::Models::CommitSummary.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TagSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :commit => commit.to_hash } end end class Tagger attr_reader :name, :email, :date def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :email, :date], 'Tagger') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @email = HttpClient::Preconditions.assert_class('email', opts.delete(:email), String) @date = HttpClient::Preconditions.assert_class('date', HttpClient::Helper.to_date_time_iso8601(opts.delete(:date)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Tagger.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :email => email, :date => date } end end class Tree attr_reader :sha, :url, :truncated, :tree def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sha, :url, :truncated, :tree], 'Tree') @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @truncated = HttpClient::Preconditions.assert_boolean('truncated', opts.delete(:truncated)) @tree = HttpClient::Preconditions.assert_class('tree', opts.delete(:tree), Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::Node) ? x : ::Io::Flow::Github::V0::Models::Node.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) Tree.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sha => sha, :url => url, :truncated => truncated, :tree => tree.map { |o| o.to_hash } } end end class TreeForm attr_reader :path, :mode, :type, :sha, :content def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:path, :mode, :type], 'TreeForm') @path = HttpClient::Preconditions.assert_class('path', opts.delete(:path), String) @mode = HttpClient::Preconditions.assert_class('mode', opts.delete(:mode), String) @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::NodeType) ? x : ::Io::Flow::Github::V0::Models::NodeType.apply(x)) @sha = (x = opts.delete(:sha); x.nil? ? nil : HttpClient::Preconditions.assert_class('sha', x, String)) @content = (x = opts.delete(:content); x.nil? ? nil : HttpClient::Preconditions.assert_class('content', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TreeForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :path => path, :mode => mode, :type => type.value, :sha => sha, :content => content } end end class TreeResult attr_reader :path, :mode, :type, :size, :sha, :url def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:path, :mode, :type, :size, :sha, :url], 'TreeResult') @path = HttpClient::Preconditions.assert_class('path', opts.delete(:path), String) @mode = HttpClient::Preconditions.assert_class('mode', opts.delete(:mode), String) @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::NodeType) ? x : ::Io::Flow::Github::V0::Models::NodeType.apply(x)) @size = HttpClient::Preconditions.assert_class('size', opts.delete(:size), Integer) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TreeResult.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :path => path, :mode => mode, :type => type.value, :size => size, :sha => sha, :url => url } end end class TreeSummary attr_reader :url, :sha def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:url, :sha], 'TreeSummary') @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @sha = HttpClient::Preconditions.assert_class('sha', opts.delete(:sha), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) TreeSummary.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :url => url, :sha => sha } end end class UnprocessableEntity attr_reader :message, :errors def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:message], 'UnprocessableEntity') @message = HttpClient::Preconditions.assert_class('message', opts.delete(:message), String) @errors = (x = opts.delete(:errors); x.nil? ? nil : HttpClient::Preconditions.assert_class('errors', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::Github::V0::Models::Error) ? x : ::Io::Flow::Github::V0::Models::Error.new(x)) }) end def to_json JSON.dump(to_hash) end def copy(incoming={}) UnprocessableEntity.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :message => message, :errors => errors.nil? ? nil : errors.map { |o| o.to_hash } } end end class User attr_reader :id, :login, :name, :email, :avatar_url, :gravatar_id, :url, :html_url, :type def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :login, :url, :html_url, :type], 'User') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), Integer) @login = HttpClient::Preconditions.assert_class('login', opts.delete(:login), String) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @email = (x = opts.delete(:email); x.nil? ? nil : HttpClient::Preconditions.assert_class('email', x, String)) @avatar_url = (x = opts.delete(:avatar_url); x.nil? ? nil : HttpClient::Preconditions.assert_class('avatar_url', x, String)) @gravatar_id = (x = opts.delete(:gravatar_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('gravatar_id', x, String)) @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String) @html_url = HttpClient::Preconditions.assert_class('html_url', opts.delete(:html_url), String) @type = (x = opts.delete(:type); x.is_a?(::Io::Flow::Github::V0::Models::OwnerType) ? x : ::Io::Flow::Github::V0::Models::OwnerType.apply(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) User.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :id => id, :login => login, :name => name, :email => email, :avatar_url => avatar_url, :gravatar_id => gravatar_id, :url => url, :html_url => html_url, :type => type.value } end end class UserEmail attr_reader :email, :verified, :primary def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:email, :verified, :primary], 'UserEmail') @email = HttpClient::Preconditions.assert_class('email', opts.delete(:email), String) @verified = HttpClient::Preconditions.assert_boolean('verified', opts.delete(:verified)) @primary = HttpClient::Preconditions.assert_boolean('primary', opts.delete(:primary)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) UserEmail.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :email => email, :verified => verified, :primary => primary } end end class UserOrg attr_reader :login def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:login], 'UserOrg') @login = HttpClient::Preconditions.assert_class('login', opts.delete(:login), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) UserOrg.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :login => login } end end end # ===== END OF SERVICE DEFINITION ===== module HttpClient class HttpHandler # Returns a client instance to use # # @param base_uri The base URI for this API # @param path the Requested full http path (including any query strings) def instance(base_uri, path) raise "Override in subclass" end end class HttpHandlerInstance # Executes a request. The provided request object will be an # instance of Net::HTTP (e.g. Net::HTTP::Get) def execute(request) raise "Override in subclass" end end class DefaultHttpHandler < HttpHandler def instance(base_uri, path) DefaultHttpHandlerInstance.new(base_uri) end end class DefaultHttpHandlerInstance < HttpHandlerInstance attr_reader :client def initialize(base_uri) @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @client = Net::HTTP.new(@base_uri.host, @base_uri.port) if @base_uri.scheme == "https" configure_ssl end end def execute(request) response = begin @client.request(request) rescue SocketError => e raise StandardError.new("Error accessing uri[#{full_uri(request.path)}]: #{e}") end case response when Net::HTTPSuccess response.body else body = response.body rescue nil raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => full_uri(request.path).to_s) end end def full_uri(path) path.start_with?(@base_uri.to_s) ? path : File.join(@base_uri.to_s, path) end # Called to configure SSL if the base uri requires it def configure_ssl @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_PEER @client.cert_store = OpenSSL::X509::Store.new @client.cert_store.set_default_paths end end class Request attr_reader :base_uri, :path, :full_uri def initialize(http_handler, base_uri, path) @http_handler = http_handler @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @path = Preconditions.assert_class('path', path, String) @full_uri = @base_uri.to_s + @path @params = nil @body = nil @auth = nil @headers = {} @header_keys_lower_case = [] end def with_header(name, value) Preconditions.check_not_blank('name', name, "Header name is required") Preconditions.check_not_blank('value', value, "Header value is required") Preconditions.check_state(!@headers.has_key?(name), "Duplicate header named[%s]" % name) @headers[name] = value @header_keys_lower_case << name.downcase self end def with_auth(auth) Preconditions.assert_class('auth', auth, HttpClient::Authorization) Preconditions.check_state(@auth.nil?, "auth previously set") if auth.scheme.name == AuthScheme::BASIC.name @auth = auth else raise "Auth Scheme[#{auth.scheme.name}] not supported" end self end def with_query(params) Preconditions.assert_class('params', params, Hash) Preconditions.check_state(@params.nil?, "Already have query parameters") @params = params self end # Wrapper to set Content-Type header to application/json and set # the provided json document as the body def with_json(json) @headers['Content-Type'] ||= 'application/json; charset=UTF-8' with_body(json) end def with_body(body) Preconditions.check_not_blank('body', body) @body = body self end def get(&block) do_request(Net::HTTP::Get, &block) end def delete(&block) do_request(Net::HTTP::Delete, &block) end def options(&block) do_request(Net::HTTP::Options, &block) end def post(&block) do_request(Net::HTTP::Post, &block) end def put(&block) do_request(Net::HTTP::Put, &block) end class PATCH < Net::HTTP::Put METHOD = "PATCH" end def patch(&block) do_request(PATCH, &block) end def do_request(klass) Preconditions.assert_class('klass', klass, Class) uri = @full_uri.dup if q = to_query(@params) uri += "?%s" % q end request = klass.send(:new, uri) # DEBUG curl = ['curl'] # DEBUG if klass != Net::HTTP::Get # DEBUG curl << "-X%s" % klass.name.split("::").last.upcase # DEBUG end if @body # DEBUG tmpfile = "/tmp/rest_client.tmp" # DEBUG File.open(tmpfile, "w") { |os| os << @body.to_s } # DEBUG curl << "-d@%s" % tmpfile request.body = @body end if @auth # DEBUG curl << "-u \"%s:%s\"" % [@auth.username, @auth.password] Preconditions.check_state(!@header_keys_lower_case.include?("authorization"), "Cannot specify both an Authorization header and an auth instance") user_pass = "%s:%s" % [@auth.username, @auth.password] encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join request.add_field("Authorization", "Basic %s" % encoded) end @headers.each { |key, value| # DEBUG curl << "-H \"%s: %s\"" % [key, value] request.add_field(key, value) } # DEBUG curl << "'%s%s'" % [@base_uri, path] # DEBUG puts curl.join(" ") raw_response = @http_handler.instance(@base_uri, request.path).execute(request) response = raw_response.to_s == "" ? nil : JSON.parse(raw_response) if block_given? yield response else response end end private def to_query(params={}) parts = (params || {}).map { |k,v| if v.is_a?(Enumerable) v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] } else "%s=%s" % [k, CGI.escape(v.to_s)] end } parts.empty? ? nil : parts.join("&") end end class ServerError < StandardError attr_reader :code, :details, :body, :uri def initialize(code, details, incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @code = HttpClient::Preconditions.assert_class('code', code, Integer) @details = HttpClient::Preconditions.assert_class('details', details, String) @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String) @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String) HttpClient::Preconditions.assert_empty_opts(opts) super(self.message) end def message m = "%s %s" % [@code, @details] if @body m << ": %s" % @body end m end def body_json @body ? JSON.parse(@body) : nil end end class PreconditionException < StandardError attr_reader :message def initialize(message) super(message) @message = message end end module Preconditions def Preconditions.check_argument(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_argument failed") end nil end def Preconditions.check_state(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_state failed") end nil end def Preconditions.check_not_nil(field_name, reference, error_message=nil) if reference.nil? raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name) end reference end def Preconditions.check_not_blank(field_name, reference, error_message=nil) if reference.to_s.strip == "" raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name) end reference end # Throws an error if opts is not empty. Useful when parsing # arguments to a function def Preconditions.assert_empty_opts(opts) if !opts.empty? raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}") end end # Requires that the provided hash has the specified keys. # @param fields A list of symbols def Preconditions.require_keys(hash, fields, error_prefix=nil) missing = fields.select { |f| !hash.has_key?(f) } if !missing.empty? msg = "Missing required fields: " + missing.join(", ") raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}") end end # Asserts that value is not nill and is_?(klass). Returns # value. Common use is # # amount = Preconditions.assert_class('amount', amount, BigDecimal) def Preconditions.assert_class(field_name, value, klass) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('klass', klass) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name]) Preconditions.check_state(value.is_a?(klass), "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_class_or_nil(field_name, value, klass) if !value.nil? Preconditions.assert_class(field_name, value, klass) end end def Preconditions.assert_boolean(field_name, value) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name) Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass), "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_boolean_or_nil(field_name, value) if !value.nil? Preconditions.assert_boolean(field_name, value) end end def Preconditions.assert_collection_of_class(field_name, values, klass) Preconditions.assert_class(field_name, values, Array) values.each { |v| Preconditions.assert_class(field_name, v, klass) } end def Preconditions.assert_hash_of_class(field_name, hash, klass) Preconditions.assert_class(field_name, hash, Hash) values.each { |k, v| Preconditions.assert_class(field_name, v, klass) } end end class AuthScheme attr_reader :name def initialize(name) @name = HttpClient::Preconditions.check_not_blank('name', name) end BASIC = AuthScheme.new("basic") unless defined?(BASIC) end class Authorization attr_reader :scheme, :username, :password def initialize(scheme, username, opts={}) @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme) @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required") @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String) HttpClient::Preconditions.assert_empty_opts(opts) end def Authorization.basic(username, password=nil) Authorization.new(AuthScheme::BASIC, username, :password => password) end end module Helper def Helper.symbolize_keys(hash) Preconditions.assert_class('hash', hash, Hash) new_hash = {} hash.each { |k, v| new_hash[k.to_sym] = v } new_hash end def Helper.to_big_decimal(value) value ? BigDecimal(value.to_s) : nil end def Helper.to_object(value) value ? (value.is_a?(Hash) ? value : JSON.parse(value)) : nil end def Helper.to_uuid(value) Preconditions.check_state(value.nil? || value.match(/^\w\w\w\w\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\w\w\w\w\w\w\w\w$/), "Invalid guid[%s]" % value) value end def Helper.to_date_iso8601(value) if value.is_a?(Date) value elsif value Date.parse(value.to_s) else nil end end def Helper.to_date_time_iso8601(value) if value.is_a?(DateTime) value elsif value DateTime.parse(value.to_s) else nil end end def Helper.date_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%d') end def Helper.date_time_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z') end TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS) FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS) def Helper.to_boolean(field_name, value) string = value.to_s.strip.downcase if TRUE_STRINGS.include?(string) true elsif FALSE_STRINGS.include?(string) false elsif string != "" raise PreconditionException.new("Unsupported boolean value[#{string}]. For true, must be one of: #{TRUE_STRINGS.inspect}. For false, must be one of: #{FALSE_STRINGS.inspect}") else nil end end end end end end end end