Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ gem 'net-ldap', require: 'net/ldap'

# INTEGRATION
gem 'jira-ruby', require: 'jira'
gem 'faraday'
gem 'faraday_middleware'
gem 'her'


# DOGFOOD
gem 'squash_ruby', require: 'squash/ruby'
Expand Down
6 changes: 6 additions & 0 deletions config/environments/common/gitlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
disabled: true
authentication:
strategy: api_key
key: "YOUR_API_KEY"
api_host: "http://ur_gitlab/api/version3/project_id/1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be nice and professional we should say "your.gitlab" or "YOUR_GITLAB" :)

6 changes: 6 additions & 0 deletions config/environments/common/redmine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
disabled: true
authentication:
strategy: api_key
key: "the_key"
api_host: "https://redmine.your.com/redmin/url"
31 changes: 31 additions & 0 deletions lib/service/gitlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Service
module Gitlab

class ApiKeyAuthentication < Faraday::Middleware
def call(env)
# do something with the request
token_parameter = { private_token: Squash::Configuration.gitlab.authentication[:key]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just say Squash::Configuration.gitlab.authentication.key too; same with all other uses of Configoro hashes


#add your api key to every request as a parameter
env[:url].query = Rack::Utils.parse_nested_query(env[:url].query).merge(token_parameter).to_param

@app.call(env).on_complete do |env|
# do something with the response
# env[:response] is now filled in
end
end

end

Her::API.setup :url => Squash::Configuration.gitlab.api_host do |connection|
connection.use ApiKeyAuthentication
connection.use Faraday::Request::UrlEncoded
connection.use Her::Middleware::DefaultParseJSON
connection.use Faraday::Adapter::NetHttp
end

class Issue
include Her::Model
end
end
end
35 changes: 35 additions & 0 deletions lib/service/redmine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Service
module Redmine

class ApiKeyAuthentication < Faraday::Middleware
def call(env)
# do something with the request
token_parameter = { key: Squash::Configuration.redmine.authentication[:key] }

env[:url].query = Rack::Utils.parse_nested_query(env[:url].query).merge(token_parameter).to_param

@app.call(env).on_complete do |env|
# do something with the response
# env[:response] is now filled in
end
end

end

Her::API.setup :url => Squash::Configuration.redmine.api_host do |connection|
#connection.response :logger # uncomment this if you need to debug your response
connection.use ApiKeyAuthentication if Squash::Configuration.redmine.authentication.strategy == "api_key"
connection.use Faraday::Request::UrlEncoded
connection.use Her::Middleware::DefaultParseJSON
connection.use Faraday::Adapter::NetHttp
end

class Issue
include Her::Model
collection_path "/issues.json"
resource_path "/issues/:id.json"
include_root_in_json true
parse_root_in_json true
end
end
end