I am trying to connect to rally using rally_api gem but it gives me error like,
Error 401 The username or password you entered is incorrect.
but when i tries to login directly through website it logs in me.
#config = {}
#config[:base_url] = "https://trial.rallydev.com/slm" # This is the default setting.
#config[:username] = "my_username"
#config[:password] = "my_pass"
#config[:workspace] = "workspace name"
#config[:project] = "project name"
Is your intent to connect to trial or production (trail.rallydev.com or rally1.rallydev.com) ?
A code making connection to Rally shown here.
#Setting custom headers
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "MyCompany"
headers.version = "1.0"
#or one line custom header
headers = RallyAPI::CustomHttpHeader.new({:vendor => "Vendor", :name => "Custom Name", :version => "1.0"})
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#company.com"
config[:password] = "password"
config[:workspace] = "Workspace Name"
config[:project] = "Project Name"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
#rally = RallyAPI::RallyRestJson.new(config)
Do you have non-alpha numeric characters in the password? (Exclamation point certainly works,but there can be characters that problematic).
Also , to set the WS API version use:
config[:version] = "v2.0"
Related
I am trying to access Ivona Speech Cloud using Ruby.
I have ported one of the code examples I found to Ruby, but I probably did something wrong at authenticating the request, since I am getting an error.
This is my implementation:
require 'http' # the gem
require 'openssl'
require 'pp'
def sign key, date, region, service, text
k_date = OpenSSL::HMAC.digest('sha256', "AWS4" + key, date)
k_region = OpenSSL::HMAC.digest('sha256', k_date, region)
k_service = OpenSSL::HMAC.digest('sha256', k_region, service)
k_signing = OpenSSL::HMAC.digest('sha256', k_service, "aws4_request")
signature = OpenSSL::HMAC.digest('sha256', k_signing, text)
signature
end
def run
access_key = "GDxxxxxxxxxxxxxxxxRA"
secret_key = "QtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlE"
region = 'eu-west-1'
date = '20160808'
service = 'tts'
body = {"Input" => {"Data" => "Hello world"}}
endpoint = "https://#{service}.#{region}.ivonacloud.com/CreateSpeech"
signature = sign secret_key, date, region, service, 'Hello World'
headers = {
"Content-Type" =>"application/json",
"Authorization" => "AWS4-HMAC-SHA256",
"Credential" => "#{access_key}/#{date}/#{region}/#{service}/aws4_request",
"SignedHeaders" => "content-type;host;x-amz-content-sha256;x-amz-date",
"Signature" => "#{signature}",
}
res = HTTP.headers(headers).post(endpoint, json: body)
p res
end
run
This is the error I am getting (line broken for legibility):
#<HTTP::Response/1.1 403 Forbidden
{"X-Amzn-Requestid"=>"18a44dd8-6dc3-11e6-808f-975692d1ee55",
"X-Amzn-Errortype"=>"IncompleteSignatureException:http://internal.amazon.com/coral/com.amazon.coral.service/",
"Content-Type"=>"application/json",
"Content-Length"=>"293",
"Date"=>"Mon, 29 Aug 2016 08:32:18 GMT"}>
Any assistance is appreciated
I would suggest using the AWS4 gem to help with this. I've made similar calls using the following format:
signer = ::AWS4::Signer.new(
access_key: "YOUR_ACCESS_KEY",
secret_key: "YOUR_SECRET_KEY",
region: "us-east-1"
)
aws_headers = {
"Content-Type" => "application/json; charset=utf8",
"Date" => Time.now.iso8601.to_s,
"Host" => "tts.us-east-1.ivonacloud.com"
}
uri = URI(endpoint)
body_params = {"Input":{"Data":"Hello world"}}.to_json
headers = signer.sign("POST", uri, aws_headers, body_params)
res = HTTP.headers(headers).post(endpoint, body: body_params)
I suspect something at Soundcloud has changed because my code has not been altered and worked fine last year.
I see:
Error: HTTP status: 422 Unprocessable Entity, Status Code: 422, playlist_struct:{:title=>"Y11 - REVO - Sop", :description=>"Y11 - REVO - Sop newchoir", :tag_list=>"Sop", :tracks=>"219269586", :format=>"json", :oauth_token=>"..."}
My oauth_token works fine.
I call:
new_playlist = #client.post('/playlists', playlist_struct)
Where #client is defined using https://github.com/soundcloud/soundcloud-ruby as:
#client = SoundCloud.new({
:client_id => clientId,
:client_secret => clientSecret,
:username => email,
:password => password
})
And playlist_struct is per the error message.
Thoughts appreciated!
Regards, M.
Full code:
require 'rubygems'
require 'soundcloud'
require 'pp'
require 'logger'
def login
# http://soundcloud.com/you/apps
clientId = '...'
clientSecret = '...'
email = '...'
password = '...'
# register a new client, which will exchange the username, password for an access_token
# NOTE: the SoundCloud API Docs advise not to use the user credentials flow in a web app.
# In any case, never store the password of a user.
#client = SoundCloud.new({
:client_id => clientId,
:client_secret => clientSecret,
:username => email,
:password => password
})
# print logged in username
puts"h1. Logged in as " + #client.get('/me').username
# updating the users profile description
end
login()
playlist_struct = {
:title => "Hello"
}
new_playlist = #client.post('/playlists', playlist_struct)
#log.info ' OK: '+new_playlist.permalink_url
Looks like the playlist_struct now needs to include
playlist: {
...
}
Around the content.
As the code worked for a couple of years before hand I'd venture this is a silent change to the API.
i'm facing several problem with API,
first:
send method asking for 'id'(message id or thread id) .. but why ?
i'm sending new message so it shouldn't require . according to Gmail Api documnetation
its optional .
https://developers.google.com/gmail/api/v1/reference/users/messages/send
ArgumentError: Missing required parameters: id.
second:
even after specify message id it return this message .
Your client has issued a malformed or illegal request.
code
require 'mime'
include MIME
msg = Mail.new
msg.date = Time.now
msg.subject = 'This is important'
msg.headers.set('Priority', 'urgent')
msg.body = Text.new('hello, world!', 'plain', 'charset' => 'us-ascii')
msg.from = {'hi#gmail.com' => 'Boss Man'}
msg.to = {
'list#example.com' => nil,
'john#example.com' => 'John Doe',
'jane#example.com' => 'Jane Doe',
}
#email = #google_api_client.execute(
api_method: #gmail.users.messages.send(:get),
body_object: {
raw: Base64.urlsafe_encode64(msg.to_s)
},
parameters: {
userId: 'me'
}
)
and of-course authentication working fine.
some other methods also working fine
like:
get list of messages(Users.messages.list)
get single message(Users.messages.get)
but
send message not working .
I think
#gmail.users.messages.send(:get) is equal to #gmail.users.messages.get
because ".send" is ruby method
so now this method is working with
#gmail.users.messages.to_h['gmail.users.messages.send']
example:
msg = Mail.new
msg.date = Time.now
msg.subject = options[:subject]
msg.body = Text.new(options[:message])
msg.from = {#_user.email => #_user.full_name}
msg.to = {
options[:to] => options[:to_name]
}
#email = #google_api_client.execute(
api_method: #gmail.users.messages.to_h['gmail.users.messages.send'],
body_object: {
raw: Base64.urlsafe_encode64(msg.to_s)
},
parameters: {
userId: 'me',
}
)
Thanks.
I think you may have a look at this gem I just built that use Gmail API and not using IMAP and SMTP like other gems:
gem install gmail-api-ruby
m = Gmail::Message.new(to: test#test.com, subject: "hello", html: "<b>this is html part<b>, text: "this is the text part")
m.deliver
gmail-api-ruby
It comes with a lot of helpful methods that you use in Gmail interface
When I try to update a custom field like this:
#rally.update('defect', 1234567890, {'c_CustomField'=>newValue})
I get :
Error on request - https://rally1.rallydev.com/slm/webservice/v2.0/defect/1234567890.js - {:errors=>["Not authorized to perform action: Invalid key"]}
The error you receive is specific to v2.0 of WS API . See Authorization section in WS API documentation. In v2.0 a security token is required to authorize Create and Update requests.
For example, if you update or create an artifact using an update or create URL, a security token must be obtained first:
GET a security token using this endpoint:
`https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize`
response:
{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "SecurityToken": "6a4b8....."}}
POST
`https://rally1.rallydev.com/slm/webservice/v2.0/HierarchicalRequirement/create?key=6a4b8...`.
However, rally_api gem 0.9.20 makes it transparent, and there is no need to request a token explicitly.
Here is an example where a custom field is updated:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "edit custom field"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
#rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "Name,FormattedID,CreationDate,Owner,UserName,c_MyCustomField"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" }
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" }
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(FormattedID = DE13)"
results = #rally.find(query)
results.each do |d|
puts "MyCustomField: #{d["c_MyCustomField"]}"
d.read
field_updates = {"c_MyCustomField" => "new text goes here"}
d.update(field_updates)
puts "MyCustomField: #{d["c_MyCustomField"]}"
end
I've been trying to write a ruby script using mechanize to batch upload a large number of images to a MediaWiki. The script runs without any errors but I suspect there is something wrong with the way I'm handling multipart forms with mechanize. The result variable at the end of the code gives no indication of success or failure, it just shows the page with all of the values filled in, wpDestFile is DezzImage.png and so on like I specified. end.submit seems to do nothing.
Below is a the complete code for uploading a single file, a few variables need filling in for it to work.
require 'rubygems'
require 'mechanize'
require 'nokogiri'
loginName = ""
loginPassword = ""
wikiUploadPage = "http://en.wikipedia.org/wiki/Special:Upload"
wikiLoginPage = "http://en.wikipedia.org/wiki/Special:UserLogin"
pathToImage = "/home/milo/image.png"
agent = Mechanize.new {|agent| agent.user_agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100513 Firefox/3.6.4" }
agent.pre_connect_hooks << lambda { |params| params[:request]['Connection'] = 'keep-alive' }
agent.follow_meta_refresh = true
agent.get(wikiLoginPage) do |page|
login_result = page.form_with(:method => /POST/) do |form|
form.wpName = loginName
form.wpPassword = loginPassword
end.submit
end
uploadPage = agent.get(wikiUploadPage)
result = uploadPage.form_with(:method => /POST/) do |form|
form.file_uploads.first.file_name = pathToImage
form.wpDestFile = "DezzImage.png"
form.wpUploadDescription = "DezzImage.png"
end.submit
We solved this elsewhere, but the problem seemed to be a misconfiguration in the MediaWiki install. Setting:
form.checkbox_with(:name => "wpIgnoreWarning").check
with the form submission seems to have addressed the issue.
Looks like you're not actually setting the POST parameter that submits the page for uploading. Try something like this:
result = uploadPage.form_with(:method => /POST/) do |form|
form.file_uploads.first.file_name = pathToImage
form.wpDestFile = "DezzImage.png"
form.wpUploadDescription = "DezzImage.png"
form.wpUpload = True
end.submit
I have the same problem.
after viewed the source code, I found the solution:
result = uploadPage.form_with(:method => /POST/) do |form|
form.file_uploads.first.file_name = pathToImage
form.wpDestFile = "DezzImage.png"
form.wpUploadDescription = "DezzImage.png"
form.checkbox_with(:name => "wpIgnoreWarning").check
end.click_button