How to use aws_account_utils to create an AWS account ? Getting error : cannot load such file -- aws_account_utils - ruby-on-rails

I want to use AWSAccountUtils in my project to create AWS account. I have installed gem aws_account_utils too. What more do I need to do or what is that I am missing ? In my controller I have defined following function and code is :
def create_aws_account
require 'aws_account_utils'
#account_details = []
#account_values = {}
aws_utils = AwsAccountUtils::AwsAccountUtils.new()
details = { 'fullName' => 'Devanshu Kumar',
'company' => 'ABC',
'addressLine1' => 'CP, Bund Garden Road',
'city' => 'Pune',
'state' => 'Maharastra',
'postalCode' => '411007',
'phoneNumber' => '1234567890',
'guess' => 'Test Account Dev' }
resp = aws_utils.create_account(account_name: 'My Test Account Devanshu Kumar',
account_email: 'devanshu.kumar#abc.com',
account_password: 'password',
account_details: details)
#account_values = {:account_number => data_disk.resp}
#account_details.push #account_values
render :json => { created_aws_account: account_details }
end
AWS Account Details Error Image

Related

More readable, DRY class with jira issue creation

In my rails app I've got a base class - creator - which creates an issue in Jira board using jira-ruby gem. I want to use it in 15 different scenarios but the only thing that will be different are required fields such as summary, description, and issuetype. To avoid duplicates I use inheritance where in each case I've got a class with only one method - required_fields.
creator
module Jira
class Creator
def initialize(webhook)
#webhook = webhook
end
def call
issue = client.Issue.build
issue.save(ticket_class.new(webhook).required_fields)
end
private
def client
#client ||= Jira::JiraConnection.new.call
end
def ticket_class
#ticket_class ||= "Issues::#{webhook.action_type_class}".constantize"
end
def required_fields; end
end
end
Sample of class inheriting from Creator:
class NewRepo < Creator
def required_fields
{
'fields' => {
'summary' => 'Create new repo <github_repo> for <Github user>',
'description' => 'This is an automatic confirmation of creating new PRIVATE repo
- <github_repo> for <Github user>',
'project' => { 'key' => 'TEST' },
'issuetype' => { 'id' => '12580' },
'customfield_15100' => 'None'
}
}
end
end
This is required_fields is not so readable, how to create such an class where hash in required_fields will be look like:
{
'fields' => {
'summary' => new_repo,
'project' => testing_project,
'issuetype' => autoresolved,
'customfield_15100' => 'None'
}
}
How to put new_repo, testing_project etc (which will be a method probably?) inside of this hash? should I merge this somehow? Or maybe there is a better way to make this hash more readable?
Here are different scenarios for required fields which I want to use depends on webhook information:
class AddMember < Creator
def required_fields
{
'fields' => {
'summary' => 'Add <Github user> collaborator to <github_repo>',
'description' => 'This is an automatic ticket confirmation of user added',
'project' => { 'key' => 'New Board' },
'issuetype' => { 'id' => '12581' },
'customfield_15100' => 'None'
}
}
end
end
class DeleteRepo < Creator
def required_fields
{
'fields' => {
'summary' => 'Recheck <Github user> deleted <github_repo>',
'description' => 'This is an automatic ticket confirmation of delete repo <github_repo>',
'project' => { 'key' => 'Second Board' },
'issuetype' => { 'id' => '1234' },
'customfield_15100' => 'None'
}
}
end
end

How to resolve "Insufficient Permission" error in Google Calendar API for Ruby?

I'm trying to use Google Calendar API for Ruby and this is code that I took from the google console site. But when I tried to run this code, I got this error.
......rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/google-api-client-0.8.6/lib/google/api_client.rb:662:in `block (2 levels) in execute!': Insufficient Permission (Google::APIClient::ClientError)
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/storage'
require 'google/api_client/auth/storages/file_store'
require 'fileutils'
APPLICATION_NAME = 'Calendar API Quickstart'
CLIENT_SECRETS_PATH = 'client_secret.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
"calendar-api-quickstart.json")
#SCOPE = 'https://www.googleapis.com/auth/calendar.readonly'
SCOPE = 'https://www.googleapis.com/auth/calendar'
def authorize
FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
file_store = Google::APIClient::FileStore.new(CREDENTIALS_PATH)
storage = Google::APIClient::Storage.new(file_store)
auth = storage.authorize
if auth.nil? || (auth.expired? && auth.refresh_token.nil?)
app_info = Google::APIClient::ClientSecrets.load(CLIENT_SECRETS_PATH)
flow = Google::APIClient::InstalledAppFlow.new({
:client_id => app_info.client_id,
# :redirect_uri => 'http://localhost:3000/auth/google_oauth2/callback',
:client_secret => app_info.client_secret,
:scope => SCOPE})
auth = flow.authorize(storage)
puts "Credentials saved to #{CREDENTIALS_PATH}" unless auth.nil?
end
auth
end
# Initialize the API
client = Google::APIClient.new(:application_name => APPLICATION_NAME)
calendar_api = client.discovered_api('calendar', 'v3')
client.authorization = authorize
=begin
# Fetch the next 10 events for the user
results = client.execute!(
:api_method => calendar_api.events.list,
:parameters => {
:calendarId => 'primary',
:maxResults => 10,
:singleEvents => true,
:orderBy => 'startTime',
:timeMin => Time.now.iso8601 })
puts "Upcoming events:"
puts "No upcoming events found" if results.data.items.empty?
results.data.items.each do |event|
start = event.start.date || event.start.date_time
puts "- #{event.summary} (#{start})"
puts "- #{event.updated} (#{start})"
# puts "- #{event.accessRole} (#{start})"
##여기에 뭔가 생기는군
end
=end
event = {
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'start' => {
'dateTime' => '2015-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'end' => {
'dateTime' => '2015-05-28T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'recurrence' => [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees' => [
{'email' => 'lpage#example.com'},
{'email' => 'sbrin#example.com'},
],
'reminders' => {
'useDefault' => false,
'overrides' => [
{'method' => 'email', 'minutes' => 24 * 60},
{'method' => 'sms', 'minutes' => 10},
],
},
}
results = client.execute!(
:api_method => calendar_api.events.insert,
:parameters => {
:calendarId => 'primary'},
:body_object => event)
event = results.data
puts "Event created: #{event.htmlLink}"
I copied the functioning part from the console site here. How can I allow the permission to use Calendar application?
For the basic read-only app, I was able to run the application because I have Calendar application enabled in the console setting but don't know how to proceed the next step. Please let me know how to solve this issue :)
I was in trouble same to you. You should change two points below:
Your application name is aimed to draw quick sample data by API. It is suitable to set your own application name. The name is one you registered in Google developer console.
You should change credentials path to your own. The path you wrote is only for quick start sample.
{File.join(Dir.home, '.credentials',"calendar-api-quickstart.json"")} >>>
{File.join(Dir.home, '.credentials',"client_secret.json")}

undefined method `values_at' for nil:NilClass when I use WashOut gem

I am new to WSDL.
Code (I have added in the view directly - for test): (Page: http://localhost:3000/ccapis )
require 'savon'
client = Savon::Client.new(wsdl: "http://localhost:3000/ccapis/wsdl")
result = client.call(:fetch_prizes, message: { :gl_id => "123456789" })
result.to_hash
And in the controller:
soap_action "fetch_prizes",
:args => { :gl_id => :string },
:return => [:array]
def fetch_prizes
glnumber = params[:gl_id ]
prize = Prize.where(:gl_id => glnumber)
prize_to_show = []
a_hash = {}
prize.each do |p|
a_hash = { :prize => p.prize.to_s, :score => p.score.to_s, :date => p.round_date.to_s }
prize_to_show.push a_hash
a_hash = nil
end
render :soap => prize_to_show
end
When I try and run this in the Console all are good and I can see the result.to_hash but when I go to http://0.0.0.0:3000/ccapis I get the error that I mentioned above.
Explanation of what I am trying to achieve:
I need to supply a WSDL for a client which fetches all the prizes based on a score.
If My approach is wrong please direct me to a document so I can have a read and get a better understanding. Thanks again.

Constantly get Authentication+failed.+API+credentials+are+incorrect

I'm trying to create simple PayPal Pay API operation, when I run this code from console it gave me response, that payment is created.
Now, when I'm tring to run it from my controller it gives me
Authentication+failed.+API+credentials+are+incorrect.
Here is my controller :
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> "denmed_1342605975_biz#gmail.com",
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => "http://127.0.0.1:3000",
"returnUrl" => "http://127.0.0.1:3000",
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
#xml = XmlSimple.xml_in(res.content)
payKey = #xml["payKey"].to_s()
payKey = payKey.tr("[]", "")
payKey = payKey[1..20]
redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"
end
Is everything ok ? Can anyone suggest reason my request fails ?
One good man found my error. I redirect user to the wrong url.
This line:
redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"
Should be:
redirect_to "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{paykey}"
I got the same error: I realized I forgot to include
sandbox_email_address: xxx#example.com
in my yml file

Where is SugarFullTest_Version2.php? (Sugar CRM and SOAP)

In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.

Resources