tinybucket2 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +86 -0
- data/Gemfile +32 -0
- data/LICENSE +21 -0
- data/README.md +387 -0
- data/Rakefile +47 -0
- data/lib/faraday_middleware/follow_oauth_redirects.rb +71 -0
- data/lib/tinybucket.rb +76 -0
- data/lib/tinybucket/api.rb +26 -0
- data/lib/tinybucket/api/base_api.rb +44 -0
- data/lib/tinybucket/api/branch_restrictions_api.rb +51 -0
- data/lib/tinybucket/api/branches_api.rb +48 -0
- data/lib/tinybucket/api/build_status_api.rb +69 -0
- data/lib/tinybucket/api/comments_api.rb +81 -0
- data/lib/tinybucket/api/commits_api.rb +97 -0
- data/lib/tinybucket/api/diff_api.rb +40 -0
- data/lib/tinybucket/api/helper.rb +27 -0
- data/lib/tinybucket/api/helper/api_helper.rb +39 -0
- data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +29 -0
- data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
- data/lib/tinybucket/api/helper/build_status_helper.rb +46 -0
- data/lib/tinybucket/api/helper/comments_helper.rb +51 -0
- data/lib/tinybucket/api/helper/commits_helper.rb +42 -0
- data/lib/tinybucket/api/helper/diff_helper.rb +31 -0
- data/lib/tinybucket/api/helper/issues_helper.rb +29 -0
- data/lib/tinybucket/api/helper/projects_helper.rb +28 -0
- data/lib/tinybucket/api/helper/pull_requests_helper.rb +58 -0
- data/lib/tinybucket/api/helper/repo_helper.rb +31 -0
- data/lib/tinybucket/api/helper/repos_helper.rb +23 -0
- data/lib/tinybucket/api/helper/team_helper.rb +45 -0
- data/lib/tinybucket/api/helper/user_helper.rb +33 -0
- data/lib/tinybucket/api/issues_api.rb +48 -0
- data/lib/tinybucket/api/projects_api.rb +26 -0
- data/lib/tinybucket/api/pull_requests_api.rb +117 -0
- data/lib/tinybucket/api/repo_api.rb +56 -0
- data/lib/tinybucket/api/repos_api.rb +28 -0
- data/lib/tinybucket/api/team_api.rb +91 -0
- data/lib/tinybucket/api/user_api.rb +66 -0
- data/lib/tinybucket/api_factory.rb +21 -0
- data/lib/tinybucket/client.rb +107 -0
- data/lib/tinybucket/config.rb +10 -0
- data/lib/tinybucket/connection.rb +84 -0
- data/lib/tinybucket/constants.rb +7 -0
- data/lib/tinybucket/enumerator.rb +47 -0
- data/lib/tinybucket/error.rb +12 -0
- data/lib/tinybucket/error/base_error.rb +14 -0
- data/lib/tinybucket/error/conflict.rb +8 -0
- data/lib/tinybucket/error/not_found.rb +8 -0
- data/lib/tinybucket/error/service_error.rb +26 -0
- data/lib/tinybucket/iterator.rb +79 -0
- data/lib/tinybucket/model.rb +25 -0
- data/lib/tinybucket/model/base.rb +45 -0
- data/lib/tinybucket/model/branch.rb +48 -0
- data/lib/tinybucket/model/branch_restriction.rb +46 -0
- data/lib/tinybucket/model/build_status.rb +57 -0
- data/lib/tinybucket/model/comment.rb +67 -0
- data/lib/tinybucket/model/commit.rb +114 -0
- data/lib/tinybucket/model/concerns.rb +19 -0
- data/lib/tinybucket/model/concerns/acceptable_attributes.rb +34 -0
- data/lib/tinybucket/model/concerns/api_callable.rb +21 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +20 -0
- data/lib/tinybucket/model/concerns/reloadable.rb +41 -0
- data/lib/tinybucket/model/concerns/repository_keys.rb +45 -0
- data/lib/tinybucket/model/error_response.rb +24 -0
- data/lib/tinybucket/model/issue.rb +48 -0
- data/lib/tinybucket/model/page.rb +45 -0
- data/lib/tinybucket/model/profile.rb +70 -0
- data/lib/tinybucket/model/project.rb +44 -0
- data/lib/tinybucket/model/pull_request.rb +160 -0
- data/lib/tinybucket/model/repository.rb +219 -0
- data/lib/tinybucket/model/team.rb +96 -0
- data/lib/tinybucket/null_logger.rb +37 -0
- data/lib/tinybucket/parser.rb +15 -0
- data/lib/tinybucket/parser/collection_parser.rb +17 -0
- data/lib/tinybucket/parser/object_parser.rb +17 -0
- data/lib/tinybucket/request.rb +59 -0
- data/lib/tinybucket/resource.rb +75 -0
- data/lib/tinybucket/resource/base.rb +35 -0
- data/lib/tinybucket/resource/branch_restrictions.rb +47 -0
- data/lib/tinybucket/resource/branches.rb +35 -0
- data/lib/tinybucket/resource/commit/base.rb +14 -0
- data/lib/tinybucket/resource/commit/build_statuses.rb +50 -0
- data/lib/tinybucket/resource/commit/comments.rb +34 -0
- data/lib/tinybucket/resource/commits.rb +46 -0
- data/lib/tinybucket/resource/forks.rb +24 -0
- data/lib/tinybucket/resource/issues.rb +35 -0
- data/lib/tinybucket/resource/projects.rb +49 -0
- data/lib/tinybucket/resource/pull_request/base.rb +20 -0
- data/lib/tinybucket/resource/pull_request/comments.rb +32 -0
- data/lib/tinybucket/resource/pull_request/commits.rb +19 -0
- data/lib/tinybucket/resource/pull_requests.rb +50 -0
- data/lib/tinybucket/resource/repos.rb +40 -0
- data/lib/tinybucket/resource/team/base.rb +24 -0
- data/lib/tinybucket/resource/team/followers.rb +15 -0
- data/lib/tinybucket/resource/team/following.rb +15 -0
- data/lib/tinybucket/resource/team/members.rb +15 -0
- data/lib/tinybucket/resource/team/repos.rb +15 -0
- data/lib/tinybucket/resource/teams.rb +22 -0
- data/lib/tinybucket/resource/user/base.rb +26 -0
- data/lib/tinybucket/resource/user/followers.rb +15 -0
- data/lib/tinybucket/resource/user/following.rb +15 -0
- data/lib/tinybucket/resource/user/repos.rb +15 -0
- data/lib/tinybucket/resource/watchers.rb +24 -0
- data/lib/tinybucket/response.rb +9 -0
- data/lib/tinybucket/response/handler.rb +23 -0
- data/lib/tinybucket/version.rb +5 -0
- data/tinybucket.gemspec +30 -0
- metadata +248 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Repo Api client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories
|
8
|
+
# repository Resource
|
9
|
+
#
|
10
|
+
# @!attribute [rw] repo_owner
|
11
|
+
# @return [String] repository owner name.
|
12
|
+
# @!attribute [rw] repo_slug
|
13
|
+
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repository slug}.
|
14
|
+
class RepoApi < BaseApi
|
15
|
+
include Tinybucket::Api::Helper::RepoHelper
|
16
|
+
|
17
|
+
attr_accessor :repo_owner, :repo_slug
|
18
|
+
|
19
|
+
# Send 'GET a repository' request
|
20
|
+
#
|
21
|
+
# @param options [Hash]
|
22
|
+
# @return [Tinybucket::Model::Repository]
|
23
|
+
def find(options = {})
|
24
|
+
get_path(
|
25
|
+
path_to_find,
|
26
|
+
options,
|
27
|
+
get_parser(:object, Tinybucket::Model::Repository)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Send 'GET a list of watchers' request
|
32
|
+
#
|
33
|
+
# @param options [Hash]
|
34
|
+
# @return [Tinybucket::Model::Page]
|
35
|
+
def watchers(options = {})
|
36
|
+
get_path(
|
37
|
+
path_to_watchers,
|
38
|
+
options,
|
39
|
+
get_parser(:collection, Tinybucket::Model::Profile)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send 'GET a list of forks' request
|
44
|
+
#
|
45
|
+
# @param options [Hash]
|
46
|
+
# @return [Tinybucket::Model::Page]
|
47
|
+
def forks(options = {})
|
48
|
+
get_path(
|
49
|
+
path_to_forks,
|
50
|
+
options,
|
51
|
+
get_parser(:collection, Tinybucket::Model::Repository)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Repos Api client
|
6
|
+
class ReposApi < BaseApi
|
7
|
+
include Tinybucket::Api::Helper::ReposHelper
|
8
|
+
|
9
|
+
# Send 'GET a list of repositories for an account' request
|
10
|
+
#
|
11
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories
|
12
|
+
# GET a list of repositories for an account
|
13
|
+
#
|
14
|
+
# @param options [Hash]
|
15
|
+
# @return [Tinybucket::Model::Page]
|
16
|
+
def list(options = {})
|
17
|
+
opts = options.clone
|
18
|
+
opts.delete(:owner)
|
19
|
+
|
20
|
+
get_path(
|
21
|
+
path_to_list(options),
|
22
|
+
opts,
|
23
|
+
get_parser(:collection, Tinybucket::Model::Repository)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Team Api client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams
|
8
|
+
# teams Endpoint
|
9
|
+
class TeamApi < BaseApi
|
10
|
+
include Tinybucket::Api::Helper::TeamHelper
|
11
|
+
|
12
|
+
# Send 'GET teams' request
|
13
|
+
#
|
14
|
+
# @param role_name [String] role name
|
15
|
+
# @param options [Hash]
|
16
|
+
# @return [Tinybucket::Model::Page]
|
17
|
+
def list(role_name, options = {})
|
18
|
+
get_path(
|
19
|
+
path_to_list,
|
20
|
+
{ role: role_name }.merge(options),
|
21
|
+
get_parser(:collection, Tinybucket::Model::Team)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Send 'GET the team profile' request
|
26
|
+
#
|
27
|
+
# @param name [String] The team's name
|
28
|
+
# @param options [Hash]
|
29
|
+
# @return [Tinybucket::Model::Team]
|
30
|
+
def find(name, options = {})
|
31
|
+
get_path(
|
32
|
+
path_to_find(name),
|
33
|
+
options,
|
34
|
+
get_parser(:object, Tinybucket::Model::Team)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Send 'GET the team members' request
|
39
|
+
#
|
40
|
+
# @param name [String] The team's name
|
41
|
+
# @param options [Hash]
|
42
|
+
# @return [Tinybucket::Model::Page]
|
43
|
+
def members(name, options = {})
|
44
|
+
get_path(
|
45
|
+
path_to_members(name),
|
46
|
+
options,
|
47
|
+
get_parser(:collection, Tinybucket::Model::Team)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Send 'GET the list of followers' request
|
52
|
+
#
|
53
|
+
# @param name [String] The team's name
|
54
|
+
# @param options [Hash]
|
55
|
+
# @return [Tinybucket::Model::Page]
|
56
|
+
def followers(name, options = {})
|
57
|
+
get_path(
|
58
|
+
path_to_followers(name),
|
59
|
+
options,
|
60
|
+
get_parser(:collection, Tinybucket::Model::Team)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Send 'GET a lisf of accounts the team is following' request
|
65
|
+
#
|
66
|
+
# @param name [String] The team's name
|
67
|
+
# @param options [Hash]
|
68
|
+
# @return [Tinybucket::Model::Page]
|
69
|
+
def following(name, options = {})
|
70
|
+
get_path(
|
71
|
+
path_to_following(name),
|
72
|
+
options,
|
73
|
+
get_parser(:collection, Tinybucket::Model::Team)
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Send 'GET the team's repositories' request
|
78
|
+
#
|
79
|
+
# @param name [String] The team's name
|
80
|
+
# @param options [Hash]
|
81
|
+
# @return [Tinybucket::Model::Page]
|
82
|
+
def repos(name, options = {})
|
83
|
+
get_path(
|
84
|
+
path_to_repos(name),
|
85
|
+
options,
|
86
|
+
get_parser(:collection, Tinybucket::Model::Repository)
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# User Api client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D
|
8
|
+
# users Endpoint
|
9
|
+
#
|
10
|
+
# @!attribute [rw] username
|
11
|
+
# @return [String]
|
12
|
+
class UserApi < BaseApi
|
13
|
+
include Tinybucket::Api::Helper::UserHelper
|
14
|
+
|
15
|
+
attr_accessor :username
|
16
|
+
|
17
|
+
# Send 'GET the user profile' request
|
18
|
+
#
|
19
|
+
# @param options [Hash]
|
20
|
+
# @return [Tinybucket::Model::Profile]
|
21
|
+
def profile(options = {})
|
22
|
+
get_path(
|
23
|
+
path_to_find,
|
24
|
+
options,
|
25
|
+
get_parser(:object, Tinybucket::Model::Profile)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Send 'GET the list of followers' request
|
30
|
+
#
|
31
|
+
# @param options [Hash]
|
32
|
+
# @return [Tinybucket::Model::Page]
|
33
|
+
def followers(options = {})
|
34
|
+
get_path(
|
35
|
+
path_to_followers,
|
36
|
+
options,
|
37
|
+
get_parser(:collection, Tinybucket::Model::Profile)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Send 'GET a list of accounts the user is following' request
|
42
|
+
#
|
43
|
+
# @param options [Hash]
|
44
|
+
# @return [Tinybucket::Model::Page]
|
45
|
+
def following(options = {})
|
46
|
+
get_path(
|
47
|
+
path_to_following,
|
48
|
+
options,
|
49
|
+
get_parser(:collection, Tinybucket::Model::Profile)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Send 'GET the user's repositories' request
|
54
|
+
#
|
55
|
+
# @param options [Hash]
|
56
|
+
# @return [Tinybucket::Model::Page]
|
57
|
+
def repos(options = {})
|
58
|
+
get_path(
|
59
|
+
path_to_repos,
|
60
|
+
options,
|
61
|
+
get_parser(:collection, Tinybucket::Model::Repository)
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
class ApiFactory
|
5
|
+
class << self
|
6
|
+
def create_instance(klass_name)
|
7
|
+
klass =
|
8
|
+
begin
|
9
|
+
name = "#{klass_name}Api".intern
|
10
|
+
Tinybucket::Api.const_get name
|
11
|
+
rescue => e
|
12
|
+
# TODO: log exception
|
13
|
+
Tinybucket.logger.error e
|
14
|
+
raise ArgumentError, 'must provide klass to be instantiated'
|
15
|
+
end
|
16
|
+
|
17
|
+
klass.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
class Client
|
5
|
+
include ::Tinybucket::Model::Concerns::Enumerable
|
6
|
+
|
7
|
+
# Get Repositories
|
8
|
+
#
|
9
|
+
# when you want to get repositories of the owner, call with owner, options.
|
10
|
+
# ex) repos('owner', options) or repos('owner')
|
11
|
+
#
|
12
|
+
# when you want to get public repositories of the owner, call with options.
|
13
|
+
# ex) repos(options) or repos
|
14
|
+
#
|
15
|
+
# @overload repos(owner, options)
|
16
|
+
# get the repositories of the owner.
|
17
|
+
# @param owner [String, Symbol] string or symbol to describe the owner.
|
18
|
+
# @option options [Hash] a hash with options
|
19
|
+
# @overload repos(options)
|
20
|
+
# get public repositories.
|
21
|
+
# @option options [Hash] a hash with options
|
22
|
+
# @return [Tinybucket::Resource::Repos] repository resource
|
23
|
+
def repos(*args)
|
24
|
+
case args.size
|
25
|
+
when 0
|
26
|
+
public_repos
|
27
|
+
when 1
|
28
|
+
case args.first
|
29
|
+
when Hash then public_repos(args.first)
|
30
|
+
when String, Symbol then owners_repos(args.first)
|
31
|
+
else raise ArgumentError
|
32
|
+
end
|
33
|
+
when 2
|
34
|
+
case args.first
|
35
|
+
when String, Symbol then owners_repos(args[0], args[1])
|
36
|
+
else raise ArgumentError
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise ArgumentError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get the repository
|
44
|
+
#
|
45
|
+
# @param owner [String] repository owner name.
|
46
|
+
# @param repo_slug [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repository slug}.
|
47
|
+
# @return [Tinybucket::Model::Repository]
|
48
|
+
def repo(owner, repo_slug)
|
49
|
+
Tinybucket::Model::Repository.new({}).tap do |m|
|
50
|
+
m.repo_owner = owner
|
51
|
+
m.repo_slug = repo_slug
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get teams
|
56
|
+
#
|
57
|
+
# @param role_name [String] role name (one of "admin", "contributor", or "member")
|
58
|
+
# @param options
|
59
|
+
# @return [Tinybucket::Resource::Teams]
|
60
|
+
def teams(role_name, options = {})
|
61
|
+
Tinybucket::Resource::Teams.new(role_name, options)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get the team
|
65
|
+
#
|
66
|
+
# @param teamname [String] the team name.
|
67
|
+
# @return [Tinybucket::Model::Team]
|
68
|
+
def team(teamname)
|
69
|
+
Tinybucket::Model::Team.new({}).tap do |m|
|
70
|
+
m.username = teamname
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get the user profile
|
75
|
+
#
|
76
|
+
# @param username [String] the user name.
|
77
|
+
# @return [Tinybucket::Model::Profile]
|
78
|
+
def user(username)
|
79
|
+
Tinybucket::Model::Profile.new({}).tap do |m|
|
80
|
+
m.username = username
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# Get public repositories
|
87
|
+
#
|
88
|
+
# @param options [Hash]
|
89
|
+
# @return [Tinybucket::Resource::Repos]
|
90
|
+
def public_repos(options = {})
|
91
|
+
raise ArgumentError unless options.is_a?(Hash)
|
92
|
+
|
93
|
+
Tinybucket::Resource::Repos.new(nil, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get Owner's repositories
|
97
|
+
#
|
98
|
+
# @param owner [String]
|
99
|
+
# @param options [Hash]
|
100
|
+
# @return [Tinybucket::Resource::Repos]
|
101
|
+
def owners_repos(owner, options = {})
|
102
|
+
raise ArgumentError unless options.is_a?(Hash)
|
103
|
+
|
104
|
+
Tinybucket::Resource::Repos.new(owner, options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Connection
|
5
|
+
DEFAULT_USER_AGENT = 'Tinybucket Ruby Bitbucket REST client'.freeze
|
6
|
+
|
7
|
+
def clear_cache
|
8
|
+
@connection = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def caching?
|
12
|
+
!@connection.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def connection(parser = nil, options = {})
|
16
|
+
conn_options = default_options(options)
|
17
|
+
clear_cache
|
18
|
+
|
19
|
+
# TODO: cache connection for each (options, parser) pairs.
|
20
|
+
Faraday.new(
|
21
|
+
conn_options.merge(builder: stack(parser, options))
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def default_options(_options)
|
28
|
+
{
|
29
|
+
headers: {
|
30
|
+
USER_AGENT: Tinybucket.config.user_agent || DEFAULT_USER_AGENT
|
31
|
+
},
|
32
|
+
ssl: { verify: false },
|
33
|
+
url: 'https://api.bitbucket.org/2.0'.freeze
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_middleware(_options)
|
38
|
+
proc do |conn|
|
39
|
+
configure_response_cache(conn)
|
40
|
+
|
41
|
+
conn.request :multipart
|
42
|
+
conn.request :url_encoded
|
43
|
+
|
44
|
+
configure_auth(conn)
|
45
|
+
|
46
|
+
conn.response :json, content_type: /\bjson$/
|
47
|
+
conn.use Tinybucket::Response::Handler
|
48
|
+
conn.use :instrumentation
|
49
|
+
|
50
|
+
conn.adapter Faraday.default_adapter
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def configure_auth(conn)
|
55
|
+
if Tinybucket.config.access_token
|
56
|
+
conn.request :oauth2, Tinybucket.config.access_token
|
57
|
+
else
|
58
|
+
oauth_secrets = {
|
59
|
+
consumer_key: Tinybucket.config.oauth_token,
|
60
|
+
consumer_secret: Tinybucket.config.oauth_secret
|
61
|
+
}
|
62
|
+
|
63
|
+
conn.request :oauth, oauth_secrets
|
64
|
+
conn.response :follow_oauth_redirects, oauth_secrets
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def configure_response_cache(conn)
|
69
|
+
return unless Tinybucket.config.cache_store_options
|
70
|
+
|
71
|
+
conn.use :http_cache, Tinybucket.config.cache_store_options
|
72
|
+
end
|
73
|
+
|
74
|
+
def stack(parser, options = {}, &block)
|
75
|
+
Faraday::RackBuilder.new(&block) and return if block_given?
|
76
|
+
|
77
|
+
# TODO: cache stack for each (options, parser) pairs
|
78
|
+
Faraday::RackBuilder.new do |conn|
|
79
|
+
conn.use parser.type, parser_options: parser.options if parser.present?
|
80
|
+
default_middleware(options).call(conn)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|