Module: Octopi

Included in:
KeySet, BranchSet, IssueSet, RepositorySet
Defined in:
lib/octopi.rb,
lib/octopi/api.rb,
lib/octopi/key.rb,
lib/octopi/tag.rb,
lib/octopi/base.rb,
lib/octopi/blob.rb,
lib/octopi/gist.rb,
lib/octopi/plan.rb,
lib/octopi/self.rb,
lib/octopi/user.rb,
lib/octopi/error.rb,
lib/octopi/issue.rb,
lib/octopi/branch.rb,
lib/octopi/commit.rb,
lib/octopi/comment.rb,
lib/octopi/resource.rb,
lib/octopi/repository.rb,
lib/octopi/file_object.rb,
lib/octopi/issue_comment.rb

Overview

Include this into your app so you can access the child classes easier. This is the root of all things Octopi.

Defined Under Namespace

Modules: Resource, Self Classes: APIError, AnonymousApi, Api, ArgumentMustBeHash, AuthApi, AuthenticationRequired, Base, Blob, Branch, BranchSet, Comment, Commit, FileObject, FormatError, Gist, InvalidLogin, Issue, IssueComment, IssueSet, Key, NotFound, Plan, Repository, RepositorySet, RetryableAPIError, Tag, User

Instance Method Summary collapse

Instance Method Details

#authenticated(options = {}, &block) ⇒ Object

The authenticated methods are all very similar. TODO: Find a way to merge them into something… better.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/octopi.rb', line 23

def authenticated(options={}, &block)
  begin
    config = config = File.open(options[:config]) { |yf| YAML::load(yf) } if options[:config]
    config = read_gitconfig
    options[:login] = config["github"]["user"]
    options[:token] = config["github"]["token"]
    
    authenticated_with(options) do
      yield 
    end
  ensure
    # Reset authenticated so if we were to do an anonymous call it would Just Work(tm)
    Api.authenticated = false
    Api.api = AnonymousApi.instance
  end
end

#authenticated_with(options, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/octopi.rb', line 40

def authenticated_with(options, &block)
  begin

    Api.api.trace_level = options[:trace] if options[:trace]
    
    raise "This version of octopi requires a token be set" if options[:token].nil?

    begin
      User.find(options[:login])
      # If the user cannot see themselves then they are not logged in, tell them so
    rescue Octopi::NotFound
      raise Octopi::InvalidLogin
    end
  
    trace("=> Trace on: #{options[:trace]}")
  
    Api.api = AuthApi.instance
    Api.api. = options[:login]
    Api.api.token = options[:token]
  
    yield
  ensure
    # Reset authenticated so if we were to do an anonymous call it would Just Work(tm)
    Api.authenticated = false
    Api.api = AnonymousApi.instance
  end
end