Using Typhoeus to POST an array to a URL - ruby

I'm using Typhoeus to post a hash to my API url. It's actually an array containing a set of hashes. Here's effectively what I'm doing:
companies = Array.new
company = { 'name' => 'Company 1' , 'company_url' => 'http://company.com' }
companies.push(company)
company2 = {'name' => 'Company 2' , 'company_url' => 'http://company2.com' }
companies.push(company2)
request = Typhoeus::Request.post("http://myapi.com/1.0/startups/create_batch",
:username => 'user',
:password => 'password',
:auth_method => :basic,
:params => {'companies' => companies} )
print "Create_batch response "+request.body
Once I run the script I get the output which states "Create_batch response Disallowed Key Characters.". I'm not sure what it's referencing at this point. I've looked over the text output of what print companies shows up but I don't see any strange code.
Anybody have any insights on what I should do?

Related

How can I get the author,price and title by knowing the ISBN search using amazon?

How can I get the author,price and title by knowing the ISBN search using amazon in codeigniter?
and
I been trying to sign up for the AProduct Advertising API registration for about 2 days, every time I get an error: We're sorry! There was an error processing your changes. Please try again. after account info step
how to get keys value of awsAccessKeyID, awsSecretKey, awsAssociateTag?
function getMetadataFromIsbn($isbn) {
// Get your own accesskey at http://aws.amazon.com/
$awsAccessKeyID = 'accesskey';
$awsSecretKey = 'secrete key';
$awsAssociateTag = 'Associate tag';
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$args = array(
'AssociateTag' => $awsAssociateTag,
'AWSAccessKeyId' => $awsAccessKeyID,
'IdType' => 'ISBN',
'ItemId' => $isbn,
'Operation' => 'ItemLookup',
'ResponseGroup' => 'Medium',
'SearchIndex' => 'Books',
'Service' => 'AWSECommerceService',
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version'=> '2009-01-06'
);

Integrating Google+ into Rails app (execute not working)

I am trying to display data from Google+ by adapting this to rails https://github.com/google/google-api-ruby-client I created a rails app, made a few tweaks to get oauth working with the client_secret.json, but when the request executes, nothing displays.
welcome_controller:
class WelcomeController < ApplicationController
def index
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
$credentials = Google::APIClient::ClientSecrets.load
# Initialize the client.
$authorization = Signet::OAuth2::Client.new(
:authorization_uri => $credentials.authorization_uri,
:token_credential_uri => $credentials.token_credential_uri,
:client_id => $credentials.client_id,
:client_secret => $credentials.client_secret,
:redirect_uri => $credentials.redirect_uris.first,
:scope => 'https://www.googleapis.com/auth/plus.login')
#client = Google::APIClient.new(
:application_name => 'X',
:application_version => 'X'
)
# Initialize Google+ API. Note this will make a request to the
# discovery service every time, so be sure to use serialization
# in your production code. Check the samples for more details.
#plus = #client.discovered_api( "plus", "v1" )
# Make an API call.
#google_plus_info = #client.execute(
:api_method => #plus.activities.list,
:parameters => {'collection' => 'public', 'userId' => 'my_num_here'}
)
#puts #google_plus_info.data #tried this
render plain: "test: #{#google_plus_info.data}" #tried this too, just returns the call name
end
end
Anyone know why I'm getting it in this case, according to the API (i thought) this was a public call? NOTE: I changed this post in response to suggestions to show my current state of work.
Try replacing $authorization.execute with plus.execute
Take a look at https://github.com/google/google-api-ruby-client-samples/tree/master/googleplus
Here's a snippet from my working code:
#client = Google::APIClient.new(
:application_name => 'X',
:application_version => 'X'
)
#client.authorization.update_token!(:access_token => 'X', :refresh_token => 'X')
#plus = #client.discovered_api( "plus", "v1" )
#google_plus_info = #client.execute(
:api_method => #plus.people.get,
:parameters => {'collection' => 'public', 'userId' => 'me'}
)

Array nested in hash for WP API?

Here's my call:
result = blog.call('wp.newPost',
1,
'user',
'pw',
{
'post_type' => 'post',
'post_content' => entry[3],
'post_name' => entry[2].downcase.split(" ").join("-"),
'comment_status' => 'closed',
'pinged' => 'closed',
'post_status' => 'publish',
'post_title' => entry[2],
'terms' => ['category' => 9]
})
This is returning an error that this post type post doesn't support one of the taxonomies given category - well, every post should have a category, so I'm thinking that my ruby is malformed. The API asks for an array with the taxonomy as a key and its ID as the value, which I think I've done here.
This is for v3.4 - here is the documentation on wp.newPost
Interestingly enough, the following code worked:
blogcontent = {
:post_type => 'post',
:post_content => entry[3],
:post_name => entry[2].downcase.split(" ").join("-"),
:comment_status => 'closed',
:pinged => 'closed',
:post_status => 'publish',
:post_title => entry[2],
:terms =>
{
:category => [9]
}
}
This converted (via the XMLRPC Writer) to the appropriate XML and registered the posts in WordPress. Turning on the XML-RPC debugging information revealed that a struct wasn't being passed unless the variable 9 was enclosed in brackets, even though it is a single value array.

CodeIgniter Payments Getting a Success Response but not Working

I'm using CodeIgniter Payments to integrate with the Paypal API. I believe I am calling the right methods because I'm getting a response of "Success" but I don't see the transaction in the Sandbox. When I use the sample DoDirectPayment file from Paypal I complete the transaction and I can see it in the sandbox.
Here is my code using CodeIgniter Payments:
//load the payment library
$this->load->spark('codeigniter-payments/0.1.4/');
//configure the parameters for the payment request
$paymentParameters = array(
'cc_type' => 'foo',
'cc_number' => 'foo',
'cc_exp' => 'foo',
'first_name' => 'foo',
'last_name' => 'foo',
'street' => 'foo',
'street2' => 'foo',
'city' => 'foo',
'state' => 'foo',
'country' => 'foo',
'postal_code' => 'foo',
'amt' => 'foo',
'currency_code' => 'USD'
);
//make the call
$paymentResponse = $this->payments->oneoff_payment('paypal_paymentspro', $paymentParameters);
//print the response
print_r($paymentResponse);
Here is the response:
stdClass Object
(
[type] => gateway_response
[status] => Success
[response_code] => 100
[response_message] => The authorization was successful.
[details] => stdClass Object
(
[gateway_response] => stdClass Object
(
[TIMESTAMP] => 2012-05-22T19:18:17Z
[CORRELATIONID] => 7939eeaa6c0c0
[ACK] => Success
[VERSION] => 66.0
[BUILD] => 2929894
[AMT] => 20.89
[CURRENCYCODE] => USD
[AVSCODE] => X
[CVV2MATCH] => M
[TRANSACTIONID] => 4RS01101TL8204042
)
[timestamp] => 2012-05-22T19:18:17Z
[identifier] => 4RS01101TL8204042
)
)
You can just switch into using other Paypal libraries. It might save you time than figuring out this problem. http://codeigniter.com/wiki/PayPal_Lib
I had this problem too.
In my case, I did not set my config driver correctly and it ended up sending all my transactions to Calvin's (Author's) default paypal sandbox account.
Double check to make sure that your API tokens are set correctly with:
$gateway_name = 'paypal_paymentspro';
$params = array(
'identifier' => *Your transaction ID from above*
);
$response = $this->payments->get_transaction_details($gateway_name, $params);
print_r($results);
Also, if you don't want to set the driver and want to do everything from your PHP file, you can always pass in your API tokens like so:
$gateway_name = 'paypal_paymentspro';
$params = array(
'identifier' => *Your transaction ID from above*
);
$config['api_username'] = *Your api username*;
$config['api_password'] = *Your api password*;
$config['api_signature'] = *Your sig*;
$response = $this->payments->get_transaction_details($gateway_name, $params);
print_r($results);

OmniAuth Facebook Authentication Nickname returning "profile.php?id=.."

I'm using Sinatra and OmniAuth, trying to authenticate using Facebook. Everything seems to be working properly except for the nickname property. My auth hash is returning something for the nickname, but it is not the person's nickname. For what I'm trying to do, getting the person's nickname is very important. And I already checked my Facebook page to make sure that I have a nickname set, and I do. It should be returning "HeroicEric".
get '/auth/:name/callback' do
auth = request.env["omniauth.auth"]
user = User.first_or_create({ :uid => auth["uid"]}, {
:uid => auth["uid"],
:username => auth["user_info"]["nickname"],
:name => auth["user_info"]["name"],
:email => auth["user_info"]["email"]
})
session[:user_id] = user.id
redirect '/user/' + user.id.to_s
end
The hash that is being returned looks like this:
"user_info"=>{
"name"=>"Eric Kelly",
"urls"=>
{
"Facebook"=>"http://www.facebook.com/profile.php?id=550432081",
"Website"=>nil
},
"nickname"=>"profile.php?id=550432081",
"last_name"=>"Kelly",
"image"=>"http://graph.facebook.com/550432081/picture?type=square",
"first_name"=>"Eric",
"email"=>"heroiceric#gmail.com"
},
The code extracting data from facebook OAuth answer is in oa-oauth-0.2.3/lib/omniauth/strategies/facebook.rb
def user_info
{
'nickname' => user_data["link"].split('/').last,
'email' => (user_data["email"] if user_data["email"]),
'first_name' => user_data["first_name"],
'last_name' => user_data["last_name"],
'name' => "#{user_data['first_name']} #{user_data['last_name']}",
'image' => "http://graph.facebook.com/#{user_data['id']}/picture?type=square",
'urls' => {
'Facebook' => user_data["link"],
'Website' => user_data["website"],
}
}
end
As you see, nickname is just a rigth part of URL. I suggest fixing facebook adapter to get an actual nickname. Facebook returns user_data filled with
{ ... "name"=>"John", "first_name"=>"John", "last_name"=>"Smith",
"link"=>"http://www.facebook.com/ujifgc", "username"=>"ujifgc", ... }
So, the username field is what you want.

Resources