Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have gem that returns next hash object
{:response=>"There was an error authenticating the sender account.", :status_code=>401}
and in my rake task i'm trying to access it's properties:
response = my_gem.execute
puts response
puts response.has_key?(:respose)
puts response[:respose]
But i can't understand why it prints
{:response=>"There was an error authenticating the sender account.", :status_code=>401}
false
Why can't i access :response property with response[:respose] ?
P.S. response[response.keys.first] works but it's very weird solution
There is a typo in the below :
puts response.has_key?(:respose)
has_key?(:respose) should be has_key?(:response).
response = {:response=>"There was an error authenticating the sender account.", :status_code=>401}
response.has_key?(:response)
# => true
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
If yes, can you point me to some resources on how to accomplish this task? Or share your expertise on this topic?
1 Get your Firebase Api key
2 Check your JWT
def firebase_verification(token)
url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=#{ENV['FIREBASE_API_KEY']}"
firebase_verification_call = HTTParty.post(url, headers: { 'Content-Type' => 'application/json' }, body: { 'idToken' => token }.to_json )
if firebase_verification_call.response.code == "200"
firebase_infos = firebase_verification_call.parsed_response
else
raise CustomError
end
end
3 Create the user
def firebase_login(token)
firebase_infos = firebase_verification(token)
raise CustomError if uid != firebase_infos['users'][0]['localId']
user = find_by(digits_id: firebase_infos['users'][0]['localId'])
if user.nil?
user = new
user.email = ''
user.password = Devise.friendly_token
user.digits_id = firebase_infos['users'][0]['localId']
user.digits_created_at = firebase_infos['users'][0]['createdAt']
end
user.phone_number = firebase_infos['users'][0]['phoneNumber']
user.access_token = token
user.save
user
end
for more details check this out
I believe that you can. Basically you are going to use firebase auth for authentication and your ruby app will get the authentication token and check if it is valid. I am not sure if there is an active ruby library to install for firebase (its always easier with a good lib) but you can use Firebase rest api to check for the token.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there any recommendation for SMS plugin which can be easily integrated with Grails?
I'm building a management system which sends customers Y/N confirmation via text message.
The cost and deliverance quality of SMS services depends on which countries you will be sending SMS to, but (prior to changing to a Swedish vendor) we have used the international vendor Clickatell with ok results.
You don't need a Grails plugin for that, just use HTTPBuilder (e.g. by including the Grails REST plugin) with Grails to call the Clickatell API according to their documentation.
Here is some old sample code (may not be working if the API has changed):
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.EncoderRegistry
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.ContentType.TEXT
def http = new HTTPBuilder(host)
http.contentType = TEXT
EncoderRegistry encoders = new EncoderRegistry();
encoders.setCharset('ISO-8859-1')
http.setEncoderRegistry(encoders)
http.request(POST) {
uri.path = 'http/sendmsg'
requestContentType = URLENC
body = [api_id: '1234567', user: 'john', password: 'doe', from: 'Company', to: NUMBER, text: 'Hello world', concat: '3', callback: '2', deliv_ack: '1']
response.success = { resp, reader ->
def msg = reader.text
if (msg.substring(0, 2) == 'ID') {
} else if (msg.substring(0, 3) == 'ERR') {
} else {
}
}
response.failure = { resp ->
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
In my config.groovy I have some code for LDAP authentication using springsecurity plugin.
grails.plugin.springsecurity.ldap.context.managerDn = CN=user,OU=Accounts,OU=Users,DC=organization,DC=com'
grails.plugin.springsecurity.ldap.context.managerPassword = 'password'
grails.plugin.springsecurity.ldap.context.server = 'ldap://ldapserver.com:389/'
grails.plugin.springsecurity.ldap.authorities.ignorePartialResultException = true // typically needed for Active Directory
grails.plugin.springsecurity.ldap.search.base = 'DC=organization,DC=com'
grails.plugin.springsecurity.ldap.search.filter="(&(sAMAccountName={0})(|(memberOf=...)(memberOf=...)(memberOf=...)))"
grails.plugin.springsecurity.ldap.search.searchSubtree = true
grails.plugin.springsecurity.ldap.auth.hideUserNotFoundExceptions = false
grails.plugin.springsecurity.providerNames=['ldapAuthProvider']
grails.plugin.springsecurity.securityConfigType = "Annotation"
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/**': ['isFullyAuthenticated()']
]
It works fine but now I need to display logged username on main page and whichever user is logged, doing some actions. How I can do that?
have you tried <sec:username/>?
username
Displays the value of the UserDetails username field if logged in.
<sec:ifLoggedIn>
Welcome Back <sec:username/>!
</sec:ifLoggedIn>
<sec:ifNotLoggedIn>
<g:link controller='login' action='auth'>Login</g:link>
</sec:ifNotLoggedIn>
I you want to get the username in a service or controller, you should use:
def springSecurityService
def someActionOrMethod(){
println springSecurityService.currentUser.username
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
// Get woeid by lati/long
HttpGet hg = new HttpGet(
"http://where.yahooapis.com/geocode?location=" + latlon + "&flags=J&gflags=R)");
HttpClient hc = new DefaultHttpClient();
HttpResponse weatherHR = hc.execute(hg);
if (weatherHR.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
if (DEBUG)
Utils.log("", "Location != HttpStatus.SC_OK");
return null;
}
I used this API and it work ok before, but It return a error since today, the HttpStatus.SC_OK is not OK. Has this API been closed? Thanks.
Yahoo has moved to paid service called BOSS but they do offer a non-commercial service:
Non-Commercial usage of Yahoo Geo API's
Yahoo! continues to fully support developer applications built on top of Placefinder and PlaceSpotter in non-commercial settings. Both services are available to you via YQL and rate limited to 2000 queries per table. Learn more about using the Placefinder and Placespotter YQL tables.
Using Placefinder you can reverse lookup a latitude and longitude:
http://developer.yahoo.com/yql/console/?q=select%20*%20from%20geo.placefinder%20where%20text%3D%2237.416275%2C-122.025092%22%20and%20gflags%3D%22R%22
which can be converted into a json request:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.placefinder%20where%20text%3D%2237.416275%2C-122.025092%22%20and%20gflags%3D%22R%22&format=json
Yes, it's closed, give a look here:
http://soup.metwit.com/post/47181933854/an-alternative-to-yahoo-weather-api
A city can also be used as location as follows:
select *
from weather.forecast
where woeid in (
select woeid
from geo.places(1)
where text="frankfurt"
) and u="c"
Where "frankfurt" can be replaced with any location of choice.
To get the Yahoo Weather WOEID by latitude and longitude, you can use this
https://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22(20,34)%22%20limit%201&diagnostics=false&format=json
And you will receive a response like the following:
{
"query":{
"count":1,
"created":"2017-03-17T20:34:50Z",
"lang":"es-AR",
"results":{
"place":{
"woeid":"1435509"
}
}
}
}
If still someone need answear. You have basic URL:
https://query.yahooapis.com/v1/public/yql?q=
Now you have to make correct YQL statement (replace city with your city name) e.x.
select * from geo.places where text="city"
Now you have to encode to URI. You can use javascript method: encodeURIComponent().
Then you have to merge basicURL and encoded YQL statement and
&format=json
So example of the whole link for San Francisco will be:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22san%20francisco%2C%20ca%22&format=json
Now from response you have to get WOEID number. You can get it by:
query>results>place>[0]>woeid
So in Javascript it will be something like:
const woeidNumber = responseObject['query']['results']['place'][0]['woeid'];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been writing my Rails application with Cucumber in TDD mode: Tests first, then the code. Now my application needs an API. What I like about cucumber is, that I can specify my tests in plain English, so even managers understand what's going on.
Is there any way I can do this for my JSON-API?
YES! This is totally possible. Have you checked out the Cucumber Book by the Pragmatic Programmer series?
Here's a quick example:
Feature: Addresses
In order to complete the information on the place
I need an address
Scenario: Addresses
Given the system knows about the following addresses:
[INSERT TABLE HERE or GRAB FROM DATABASE]
When client requests GET /addresses
Then the response should be JSON:
"""
[
{"venue": "foo", "address": "bar"},
{ more stuff }
]
"""
STEP DEFINITION:
Given(/^the system knows about the following addresses:$/) do |addresses|
# table is a Cucumber::Ast::Table
File.open('addresses.json', 'w') do |io|
io.write(addresses.hashes.to_json)
end
end
When(/^client requests GET (.*)$/) do |path|
#last_response = HTTParty.get('local host url goes here' + path)
end
Then /^the response should be JSON:$/ do |json|
JSON.parse(#last_response.body).should == JSON.parse(json)
end
ENV File:
require File.join(File.dirname(__FILE__), '..', '..', 'address_app')
require 'rack/test'
require 'json'
require 'sinatra'
require 'cucumber'
require 'httparty'
require 'childprocess'
require 'timeout'
server = ChildProcess.build("rackup", "--port", "9000")
server.start
Timeout.timeout(3) do
loop do
begin
HTTParty.get('local host here')
break
rescue Errno::ECONNREFUSED => try_again
sleep 0.1
end
end
end
at_exit do
server.stop
end
You can definitely achieve this. You can write step definitions to assert/verify your json responses. Something like this
Given a username and password
When I try to login via the API
Then I should get logged in
While this works, this just tests the API ( controllers/actions ) work or not, ie more like "functional" testing, not Acceptance testing. As such you are not going to test the API consumer itself.