Skip to content
Browse files

added PhraseApp hook

  • Loading branch information...
1 parent 024f2fd commit e036f6ab049abcbbdecd9a0cd6b841779a2ff9ad @docstun docstun committed
Showing with 87 additions and 0 deletions.
  1. +13 −0 docs/phraseapp
  2. +42 −0 lib/services/phraseapp.rb
  3. +32 −0 test/phraseapp_test.rb
View
13 docs/phraseapp
@@ -0,0 +1,13 @@
+PhraseApp Translation Management
+================================
+
+*Your companion to become a global player. The translation management software for websites and mobile apps.*
+
+This service lets you connect your GitHub repository to an existing [PhraseApp](https://phraseapp.com) translation project to automatically push new translations from your locale files into PhraseApp.
+
+Read more: [Documentation](https://phraseapp.com/docs)
+
+Install Notes
+-------------
+
+Just add your project **auth token** to the hook configuration. You find your token on your project overview page after creating the first project in PhraseApp.
View
42 lib/services/phraseapp.rb
@@ -0,0 +1,42 @@
+class Service::Phraseapp < Service
+ include Service::HttpHelper
+
+ title "PhraseApp"
+
+ string :auth_token
+
+ white_list :auth_token
+
+ default_events :push
+
+ url "https://phraseapp.com"
+ logo_url "https://phraseapp.com/assets/github/phraseapp-logo.png"
+
+ maintained_by github: "docstun"
+
+ supported_by web: "https://phraseapp.com/contact",
+ email: "info@phraseapp.com",
+ twitter: "@phraseapp"
+
+ def receive_push
+ auth_token = required_config_value("auth_token")
+ raise_config_error "Invalid auth token" unless auth_token.match(/^[A-Za-z0-9]+$/)
+
+ body = generate_json(hook_params)
+ http_post(hook_uri, body) do |request|
+ request.params[:auth_token] = auth_token
+ end
+ end
+
+protected
+ def hook_uri
+ "https://phraseapp.com:443/api/v1/hooks/github"
+ end
+
+ def hook_params
+ {
+ data: data,
+ payload: payload
+ }
+ end
+end
View
32 test/phraseapp_test.rb
@@ -0,0 +1,32 @@
+require File.expand_path('../helper', __FILE__)
+
+class PhraseappTest < Service::TestCase
+ include Service::HttpTestMethods
+
+ def test_push
+ test_auth_token = "footoken"
+
+ data = {
+ "auth_token" => test_auth_token
+ }
+
+ payload = {'commits'=>[{'id'=>'test'}]}
+ svc = service(data, payload)
+
+ @stubs.post "/api/v1/hooks/github" do |env|
+ body = JSON.parse(env[:body])
+
+ assert_equal("phraseapp.com", env[:url].host)
+ assert_equal("post", env[:method].to_s)
+ [200, {}, '']
+ end
+
+ svc.receive_push
+ @stubs.verify_stubbed_calls
+ end
+
+ def service_class
+ Service::Phraseapp
+ end
+end
+

0 comments on commit e036f6a

Please sign in to comment.
Something went wrong with that request. Please try again.