Module: Octopi

Included in:
KeySet, BranchSet, IssueSet, RepositorySet, TreeSet
Defined in:
lib/octopi.rb,
lib/octopi/key.rb,
lib/octopi/api.rb,
lib/octopi/tag.rb,
lib/octopi/user.rb,
lib/octopi/base.rb,
lib/octopi/tree.rb,
lib/octopi/plan.rb,
lib/octopi/gist.rb,
lib/octopi/blob.rb,
lib/octopi/self.rb,
lib/octopi/error.rb,
lib/octopi/issue.rb,
lib/octopi/branch.rb,
lib/octopi/commit.rb,
lib/octopi/version.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, Tree, TreeSet, User

Constant Summary

VERSION =
"0.4.5"

Instance Method Summary (collapse)

Instance Method Details

- (Object) authenticated(options = {}, &block)

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/octopi.rb', line 28

def authenticated(options={}, &block)
  begin
    if options[:config]
      config = YAML.load_file(options[:config])
    else
      config = read_gitconfig
    end

    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

- (Object) authenticated_with(options, &block)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/octopi.rb', line 49

def authenticated_with(options, &block)
  begin

    if options[:token].nil? && !options[:password].nil?
      options[:token] = grab_token(options[:login], options[:password])
    end
    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

    Api.api = AuthApi.instance
    Api.api.trace_level = options[:trace] if options[:trace]
    Api.api. = options[:login]
    Api.api.token = options[:token]

    trace("=> Trace on: #{options[:trace]}")

    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