Module: Octopi
- Included in:
- KeySet, BranchSet, IssueSet, RepositorySet, TreeSet
- 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/tree.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/version.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 collapse
- VERSION =
"0.4.5"
Instance Method Summary collapse
-
#authenticated(options = {}, &block) ⇒ Object
The authenticated methods are all very similar.
- #authenticated_with(options, &block) ⇒ Object
Instance Method Details
#authenticated(options = {}, &block) ⇒ Object
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(={}, &block) begin if [:config] config = YAML.load_file([:config]) else config = read_gitconfig end [:login] = config["github"]["user"] [:token] = config["github"]["token"] authenticated_with() 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
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(, &block) begin if [:token].nil? && ![:password].nil? [:token] = grab_token([:login], [:password]) end begin User.find([: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 = [:trace] if [:trace] Api.api.login = [:login] Api.api.token = [: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 |