diff --git a/Gemfile b/Gemfile index e38df340..f1f63815 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/config/environments/common/gitlab.yml b/config/environments/common/gitlab.yml new file mode 100644 index 00000000..f6262a24 --- /dev/null +++ b/config/environments/common/gitlab.yml @@ -0,0 +1,6 @@ +--- +disabled: true +authentication: + strategy: api_key + key: "YOUR_API_KEY" +api_host: "http://ur_gitlab/api/version3/project_id/1" diff --git a/config/environments/common/redmine.yml b/config/environments/common/redmine.yml new file mode 100644 index 00000000..285088cd --- /dev/null +++ b/config/environments/common/redmine.yml @@ -0,0 +1,6 @@ +--- +disabled: true +authentication: + strategy: api_key + key: "the_key" +api_host: "https://redmine.your.com/redmin/url" diff --git a/lib/service/gitlab.rb b/lib/service/gitlab.rb new file mode 100644 index 00000000..535fa0fd --- /dev/null +++ b/lib/service/gitlab.rb @@ -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]} + + #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 diff --git a/lib/service/redmine.rb b/lib/service/redmine.rb new file mode 100644 index 00000000..c907010e --- /dev/null +++ b/lib/service/redmine.rb @@ -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