diff --git a/lib/motion-phrase.rb b/lib/motion-phrase.rb index d7bdd7f..7a5374f 100644 --- a/lib/motion-phrase.rb +++ b/lib/motion-phrase.rb @@ -4,8 +4,6 @@ require "motion/project/phrase" require "motion-cocoapods" -require "bubble-wrap" -require "afmotion" Motion::Project::App.setup do |app| Dir.glob(File.join(File.dirname(__FILE__), 'motion-phrase/**/*.rb')).each do |file| @@ -15,7 +13,7 @@ app.files.unshift("./app/phrase_config.rb") app.pods do - pod 'AFNetworking' + pod 'AFNetworking', '>= 2.5.0' end end diff --git a/lib/motion-phrase/api_client.rb b/lib/motion-phrase/api_client.rb index 591ecb7..4c47af3 100644 --- a/lib/motion-phrase/api_client.rb +++ b/lib/motion-phrase/api_client.rb @@ -20,26 +20,23 @@ def storeTranslation(keyName, content, fallbackContent, currentLocale) skip_verification: true, api_client: API_CLIENT_IDENTIFIER, } - client.post("translations/store", authenticated(data)) do |result| - if result.success? - log "Translation stored [#{data.inspect}]" - elsif result.failure? - log "Error while storing translation [#{data.inspect}]" - end - end + + client.POST("translations/store", parameters:authenticated(data), success:lambda {|task, responseObject| + log "Translation stored [#{data.inspect}]" + }, failure:lambda {|task, error| + log "Error while storing translation [#{data.inspect}]" + }) end private def client - @client ||= buildClient - end - - def buildClient - AFMotion::Client.build_shared(API_BASE_URI) do - header "Accept", "application/json" - request_serializer :json - response_serializer :json + Dispatch.once do + @client = begin + _client = AFHTTPSessionManager.alloc.initWithBaseURL(NSURL.URLWithString(API_BASE_URI)) + _client + end end + @client end def log(msg="") diff --git a/lib/motion-phrase/nsstring.rb b/lib/motion-phrase/nsstring.rb index 18ad107..2c0d8e0 100644 --- a/lib/motion-phrase/nsstring.rb +++ b/lib/motion-phrase/nsstring.rb @@ -16,11 +16,26 @@ def phraseEnabled? PHRASE_ENABLED == true && development? end - def development? - App.development? + def currentLocaleName + currentLocale.localeIdentifier end - def currentLocaleName - App.current_locale.localeIdentifier + # @return [NSLocale] locale of user settings + def currentLocale + languages = NSLocale.preferredLanguages + if languages.count > 0 + return NSLocale.alloc.initWithLocaleIdentifier(languages.first) + else + return NSLocale.currentLocale + end + end + + def environment + RUBYMOTION_ENV end + + def development? + environment == 'development' + end + end diff --git a/lib/motion-phrase/version.rb b/lib/motion-phrase/version.rb index 8ea6222..7ab4eea 100644 --- a/lib/motion-phrase/version.rb +++ b/lib/motion-phrase/version.rb @@ -1,3 +1,3 @@ module MotionPhrase - VERSION = "0.0.5" + VERSION = "0.0.6" end diff --git a/motion-phrase.gemspec b/motion-phrase.gemspec index b10c89e..3b25ae4 100644 --- a/motion-phrase.gemspec +++ b/motion-phrase.gemspec @@ -16,8 +16,6 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] gem.add_dependency 'phrase' - gem.add_dependency 'afmotion', '>= 2.0' - gem.add_dependency 'bubble-wrap' gem.add_dependency 'motion-cocoapods' gem.add_development_dependency 'rake' end