From fa5cfe2454315c4a2d96cfe843ca49443e8cf9dd Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 6 Feb 2013 22:36:25 -0600 Subject: [PATCH 1/3] add redmine and gitlab issue api support re https://github.com/remiprev/her --- Gemfile | 4 ++++ lib/service/gitlab.rb | 31 +++++++++++++++++++++++++++++++ lib/service/redmine.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 lib/service/gitlab.rb create mode 100644 lib/service/redmine.rb 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/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..872f69a3 --- /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, :ssl => {:verify => false} 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 From 7e15fe3fdeafd715db3566ebad6e4704dbfc760a Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 6 Feb 2013 22:44:19 -0600 Subject: [PATCH 2/3] issue service configs --- config/environments/common/gitlab.yml | 6 ++++++ config/environments/common/redmine.yml | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 config/environments/common/gitlab.yml create mode 100644 config/environments/common/redmine.yml 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" From 4aded52f29ce46a13ea0c4c1f4473544ee998d57 Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 6 Feb 2013 23:09:19 -0600 Subject: [PATCH 3/3] don't force ssl verify to false certificate was just bad on test server --- lib/service/redmine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service/redmine.rb b/lib/service/redmine.rb index 872f69a3..c907010e 100644 --- a/lib/service/redmine.rb +++ b/lib/service/redmine.rb @@ -16,7 +16,7 @@ def call(env) end - Her::API.setup :url => Squash::Configuration.redmine.api_host, :ssl => {:verify => false} do |connection| + 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