Class: GP::Ruby::Client
- Inherits:
-
Object
- Object
- GP::Ruby::Client
- Defined in:
- lib/gp-ruby-client.rb
Constant Summary collapse
- @@cache_control =
CacheControl.new
- @@locale =
""- @@just_started =
true- @@use_service =
true
Instance Method Summary collapse
- #disable_service ⇒ Object
- #enable_service ⇒ Object
- #get_bundle_id ⇒ Object
- #get_cache_control ⇒ Object
- #get_default_locale ⇒ Object
- #get_locale ⇒ Object
- #get_rest_client ⇒ Object
- #get_service_account ⇒ Object
-
#initialize(bundle_id) ⇒ Client
constructor
A new instance of Client.
- #set_bundle_id(bundle_id) ⇒ Object
- #set_locale(locale) ⇒ Object
Constructor Details
#initialize(bundle_id) ⇒ Client
Returns a new instance of Client.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gp-ruby-client.rb', line 47 def initialize(bundle_id) @@bundle_id = bundle_id if @@use_service && (Time.now - @@cache_control.get_last_accessed_time >= @@cache_control.get_ttl || @@just_started) @@just_started = false @@cache_control.set_last_accessed_time(Time.now) backend = {} I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(backend), I18n.backend) @@service_account = ServiceAccount.new if @@service_account.nil? raise "No valid service account" end @@rest_client = RESTClient.new(@@service_account, @@bundle_id, @@locale) end end |
Instance Method Details
#disable_service ⇒ Object
94 95 96 |
# File 'lib/gp-ruby-client.rb', line 94 def disable_service @@use_service = false end |
#enable_service ⇒ Object
98 99 100 |
# File 'lib/gp-ruby-client.rb', line 98 def enable_service @@use_service = true end |
#get_bundle_id ⇒ Object
66 67 68 |
# File 'lib/gp-ruby-client.rb', line 66 def get_bundle_id @@bundle_id end |
#get_cache_control ⇒ Object
82 83 84 |
# File 'lib/gp-ruby-client.rb', line 82 def get_cache_control @@cache_control end |
#get_default_locale ⇒ Object
102 103 104 |
# File 'lib/gp-ruby-client.rb', line 102 def get_default_locale request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first end |
#get_locale ⇒ Object
74 75 76 |
# File 'lib/gp-ruby-client.rb', line 74 def get_locale @@locale end |
#get_rest_client ⇒ Object
90 91 92 |
# File 'lib/gp-ruby-client.rb', line 90 def get_rest_client @@rest_client end |
#get_service_account ⇒ Object
86 87 88 |
# File 'lib/gp-ruby-client.rb', line 86 def get_service_account @@service_account end |
#set_bundle_id(bundle_id) ⇒ Object
70 71 72 |
# File 'lib/gp-ruby-client.rb', line 70 def set_bundle_id(bundle_id) @@bundle_id = bundle_id end |
#set_locale(locale) ⇒ Object
78 79 80 |
# File 'lib/gp-ruby-client.rb', line 78 def set_locale(locale) @@locale = locale end |