I am using Devise+Omniauth , and I defined my own doorkeeper strategy to add a language option
In config/initializers/devise.rb , I set up :
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale}
which initially set lang to :en ( default locale )
this works fine and send the lang options to the remote server for Doorkeeperprocessing
now, how can I change this parameter in my client calling controller ?
I tried to use :
def index
I18n.locale = :fr
Rails.application.config.middleware.use OmniAuth::Builder do
provider :doorkeeper, :setup => lambda{|env| env['omniauth.strategy'].options[:authorize_params][:lang] = env['rack.session'][I18n.locale] }
end
but I got an error :
RuntimeError (can't modify frozen Array):
app/controllers/home_controller.rb:7:in `index'
Is there any better way to do it ? thanks for help
I modified the config/initializers/devise.rb, adding :setup => true
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale},
:setup => true
and I modified my doorkeeper strategy, to include the setup_phase, in which I set the lang option to the current locale.
def setup_phase
request.env['omniauth.strategy'].options[:authorize_params][:lang] = request.params["locale"]
end
Related
When a custom attribute is set on a user from googles admin page I am unable to see it in their Google_Service_Directory_User object the client has this scope and is able to see the users data but no attributes are shown.
$client->setScopes(
[
Google_Service_Directory::ADMIN_DIRECTORY_USER_READONLY,
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_READONLY,
]
);
I would have expected it to be in the customSchemas but that is null for all the users
When requesting user's informations, you need to set the projection parameter to FULL when using the method users.get (projection parameter is also avaible with method users.list). Default settings to not return custom schemas. You can have more informations here (Google documentation).
You seem to be using PHP (I've never coded in PHP so I may be wrong), so the request should look like this:
$optParams = array(
'userKey' => 'my_customer#example.com',
'projection' => 'full', // or maybe 'FULL' ?
);
$results = $service->users->get($optParams);
If you only want the return some of the schemas, then use :
$optParams = array(
'userKey' => 'my_customer#example.com',
'projection' => 'custom', // or maybe 'CUSTOM' ?,
'customFieldMask' => 'A comma-separated list of schema names'
);
$results = $service->users->get($optParams);
I keep getting the same error since I upgraded to:
gem 'twilio-ruby', '~> 5.0.0.rc4'
The call was successful set to Twilio, but the getting some error.
app/controllers/home_controller.rb:59:in `rescue in call'
require "rubygems"
require "twilio-ruby"
def call
#twilio = Twilio::REST::Client.new account_sid, auth_token
begin
#call = #twilio.account.calls.create({
:to => ,
:from => twilio_number,
:url => url,
:method => "GET",
:if_machine => "Hangup",
:timeout => "20"
})
# Getting current call status (seems like error here...!)
get_status(#call.sid)
rescue Twilio::REST::RequestError => error
#err_msg = error.message
puts #err_msg
#returned error is like below:
#NameError (uninitialized constant Twilio::REST::RequestError)
end
end
Code for getting current call status:
def get_status(sid)
#twilio = Twilio::REST::Client.new account_sid, auth_token
#call = #twilio.account.calls.get(sid)
puts "Process Status : " + #call.status
return #call.status
end
Please help to figure it out.
Thank you!
For version 5, Try Twilio::REST::RestError.
This is documented here:
There are new classes to rescue errors from. The new library now uses the Twilio::REST::RestError class.
We have a hybrid app built using Cordova and it has a login user and password field. The applicatio is developed based on EmberJs stack. We are using Calabash 1.* version and other components works fine except all text boxes.
I am able to successfully query the input elements using the below code in console.
query("systemWebview css:'input'")
I get the below query result in console. But text value is always empty even if I enter some value.
{
"class" => "ember-view ember-text-field",
"nodeType" => "ELEMENT_NODE",
"id" => "ember555",
"textContent" => "",
"html" => "<input id=\"ember555\" class=\"ember-view ember-tex
ld\" placeholder=\"Enter User name\" type=\"text\">",
"rect" => {
"y" => 202,
"x" => 0,
"center_x" => 360,
"height" => 74,
"width" => 720,
"top" => 76,
"left" => 0,
"center_y" => 238
},
"nodeName" => "INPUT",
"webView" => "NoResourceEntry-100"
},
In the Ruby section, I have the below code and it also returns empty value.
query(objectName, :textContent).first
Any help is appreciated. Thanks in advance.
Code
query "UIWebView", :calabashStringByEvaluatingJavaScript => "document.querySelectorAll('input#ember555')[0].value"
Explanation
Breaking it down,
1.
query "UIWebView",
Gets the webview.
2.
:calabashStringByEvaluatingJavaScript => ...
This is a selector which calabash-ios-server adds to webviews such that any webview (UIWebView or WKWebView) should respond to it. The selector is invoked on the result of query "UIWebView"
3.
"document.querySelectorAll('input#ember555')[0].value"
This is a standard javascript selector that you can tweak as necessary to get your element. E.g., you could use document.getElementById() or whatever is most convenient. This string of javascript is used as an argument to the calabashStringByEvaluatingJavaScript selector.
I realize it would be nice to have the text just returned as part of the object, I'll check with the team and see if we should file an issue (or, feel free to file one yourself at https://github.com/calabash/calabash-ios-server/issues ).
Thanks to #christoper, I found some working solution for android.
evaluate_javascript("systemWebView", "return document.getElementById('nicknameid').value;")
The same logic works for checkbox validation too.
I have a simple spec testing the creation of an object of the Baseline class.
it "allows a user to create a baseline score with valid content" do
expect(#user.baselines.count).to eq(0)
#baseline = post(:create, :user_id => #user.id, :baseline => valid_attributes)
expect(response).to redirect_to '/patients/list'
expect(flash[:notice]).to eq("Baseline scores for case #{#baseline.case_id} was successfully created.")
expect(Baseline.all.count).to eq(1)
end
But I get this. I am uncertain where to begin with this - I am uncertain why I can't access the case_id attribute of #baseline.
NoMethodError:undefined method `case_id' for <ActionController::TestResponse:0x007f8f5ab4f3c0>
Just to show...these are the valid attributes
let(:valid_attributes) do {
:dx1 => "IPF",
:dxcon1 => 100,
:db1 => "Progressive",
:dbcon1 => 100,
:mgt=> "Drugs",
:biopsy => "Yes",
:patient_id => #patient.id,
:case_id => #patient.case,
}
end
post doesn't return a model instance it returns a TestResponse object which gives you access to headers, status code, etc. To access the object created as a side effect of calling the :create action you can do Baseline.last (in this case Baseline.first would also work since there are no existing baseline objects)
Also note - if you have an instance variable named #baseline that is assigned in the controller you can access that with assigns(:baseline)
expect(assigns[:baseline]).to be_a(Baseline)
I have a module called appserver in my puppet modules.
In that module manifests I have a params.pp file which is inherited by init.pp file.
In params.pp file I have the following data structure.
$servers = {
appserver-mgr => { axis2 => {subDomain => 'mgt',},
carbon => {subDomain => 'mgt',},
serverOptions => '-Dsetup',
server_home => $carbon_home, },
appserver-wkr => { axis2 => {subDomain => 'worker', members => ['appserver-mgr2-ip']},
carbon => {subDomain => 'worker',},
serverOptions => '-DworkerNode=true',
server_home => $carbon_home, },
}
In my init.pp file I'm filling my templates as follows using the said data structure.
define fill_templates($axis2, $carbon, $clustering, $serverOptions, $server_home) {
$ipAdd = $::ipaddress
$hostName = $::hostname
if $hostName == "${name}" {
notify {"host name match found for $hostName for $ipAdd":}
file { "${server_home}/repository/conf/axis2/axis2.xml":
ensure => file,
content => template('appserver/axis2.xml.erb'),
}
->
file { "${server_home}/repository/conf/carbon.xml":
ensure => file,
content => template('appserver/carbon.xml.erb'),
}
->
file { "${server_home}/repository/conf/tomcat/catalina-server.xml":
ensure => file,
content => template('appserver/catalina-server.xml.erb'),
}
}
}
As per the current method, if a matching node is found (say appserver-mgr) the respective data structure values are retrieved and applied to the templates.
Currently these scripts are working as expected.
Now I want to change it as follows.
I have a cluster containing following nodes.
appserver-mgr-1
appserver-mgr-2
appserver-mgr-3
appserver-wkr-1
appserver-wkr-2
appserver-wkr-3
appserver-wkr-4
appserver-wkr-5
By using the same data structure in params.pp file, how can I apply the appserver-mgr configuration to *.mgr nodes 1-3 and appserver-wkr configuration to *.wkr nodes 1-5?
Can I use regular expressions for this task?
I'm quite sure that it would be possible to bend the Puppet DSL to do what you need here. However, the far better approach to this issue is Hiera.
node /appserver-mgr/ {
$node_class = 'appserver'
$node_subclass = 'manager'
}
node /appserver-wrk/ {
$node_class = 'appserver'
$node_subclass = 'worker'
}
Use the node_class and node_subclass variables in your Hierarchy.
# /etc/puppet/hiera.yaml
---
:backends:
- yaml
:yaml:
:datadir: /etc/puppet/hieradata
:hierarchy:
- "%{::clientcert}"
- "class-%{node_class}-%{node_subclass}"
- "class-%{node_class}"
- common
Now you can define your data right in the YAML for Hiera, instead of params.pp.
# /etc/puppet/hieradata/class-appserver-manager.yaml
servers:
axis2:
subDomain: mgt
carbon:
subDomain: mgt
serverOptions: -Dsetup
server_home: %{carbon_home}
and for the worker:
# /etc/puppet/hieradata/class-appserver-worker.yaml
servers:
axis2:
subDomain: worker
members:
- appserver-mgr2-ip
carbon:
subDomain: worker
serverOptions: -DworkerNode=true
server_home: %{carbon_home}
In your params class, the following then suffices:
$servers = hiera('servers')
Or you don't even bother with the params class, and just replace the uses of the $servers variable with hiera calls. But doing just one call in a params style class is a good practice.
Note: Using the variable value %{carbon_home} from Hiera is somewhat dangerous, you might want to hardcode the actual value in the YAML there.