jira-ruby: issue.save returning false - ruby

I am trying to create an issue with jira-ruby in the terminal. So far I have done the following (where username, password, site and project have been replaced with the proper values). I have been able to fetch issues, but not to create them. Jira-ruby return false when i try and save an issue
options = {
:username => "username",
:password => "password",
:site => 'site',
:context_path => '',
:auth_type => :basic
}
client = JIRA::Client.new(options)
issue = client.Issue.build
issue.save({
"fields" => {
"summary" => "blarg from in example.rb",
"project" => {"key" => "mykey"},
"issuetype" => {"id" => "1"}
}
})
=> false
issue.attrs
=> {"errorMessages"=>[], "errors"=>{"issuetype"=>"issue type is required"}, "summary"=>"blarg from in example.rb", "key"=>"somekey", "id"=>"someid", "self"=>"site", "exception"=>{"class"=>"Net::HTTPBadRequest", "code"=>"400", "message"=>"Bad Request"}}
What is the problem?

Related

Savon: Wrong Element Name Prefix. How can I change it?

So here is the code that I have:
resp = client.call(
:producer_query,
message: {
'cmn:Carrier' => '',
'cmn:ProducerCriteria' => { 'cmn:EntityType' => 'Individual',
'cmn:CustomerId' => 5555,
:attributes! => {'CustomerId' => {'type' => 'AGENTCD'}}},
'cmn:SectionConfiguration' => { 'cmn:SectionType' => 'Associations', :attributes! => {'cmn:SectionType' => {'activeOnly' => 'false'}}},
:attributes! => { 'cmn:Carrier' => { "id" => 55555 }}
}
) do
wsse_auth ENV['ID'], ENV['PASSWORD'], :digest
end
And it produces something that looks like:
<soapenv:Body>
<cmn:ProducerQuery>
<cmn:Carrier id="5555"/>
<cmn:ProducerCriteria>
<cmn:EntityType>Individual</cmn:EntityType>
<cmn:CustomerId>55555</cmn:CustomerId>
</cmn:ProducerCriteria>
<cmn:SectionConfiguration>
<cmn:SectionType activeOnly="false">Associations</cmn:SectionType>
</cmn:SectionConfiguration>
</cmn:ProducerQuery>
</soapenv:Body>
I've added in the 'cmn' to everything, but the ProducerQuery to make it match what I think it should be. However, I think it really should read 'tran' instead. I can control the 'cmn' for everything but the part that reads <cmn:ProducerQuery>. How can I make it read <cmn:ProducerQuery>?

Ruby Curl::Multi.http 302 redirect problems

I seem to be having a problem with 302 redirects using curb (Ruby's curl programs)
Here's the code snippet that is ** NOT working** (it's NOT doing the 302 redirect)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'}
multi_options = {:pipeline => true}
url_fields = [
{
:url => 'https://x.y.z/webapps/login/',
:method => :post,
:follow_location => true,
:enable_cookies => true,
:useragent => 'curb',
:post_fields => {
'user_id' => 'xxxx',
'password' => 'xxxx',
'action' => 'login',
'encoded_pw' => Base64.strict_encode64('xxxx')},
}
]
Curl::Multi.http(url_fields,{:pipeline => true}) do |easy, code, method|
puts easy.header_str
end
Here's the code snippet that appears to be working (it's doing the 302 redirect)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'}
multi_options = {:pipeline => true}
url_fields = [
{ :url => 'https://x.y.z/webapps/login/',
:post_fields => {
'user_id' => 'xxxx',
'password' => 'yyyy',
'action' => 'login',
'encoded_pw' => Base64.strict_encode64('yyyy')}}
]
Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
# do something interesting with the easy response
puts easy.last_effective_url
end
Question: Why is the first block not doing the 302 redirect as expected? :follow_location is set to true?
Thanks in advance!
Let me know if you need more information

Upload Captions YouTube Data API ruby

I am trying to upload captions to YouTube using the Data API. However I can't find in the reference or in the forum any example in Ruby. In specific how to send the actual caption file (xml).
body = {
:snippet => {
:videoId => videoId,
:language => "English",
:name => "English"
}
}
captions_insert_response = client.execute(
:api_method => youtube.captions.insert,
:parameters => {
:part => body.keys.join(',')
},
:body_object => body
)
where and how do I add the caption file? I tried doing it like uploading a video, but it didn't seem to work. This line was added after ":body_object"
:media => Google::APIClient::UploadIO.new(captions_file, 'text/xml')
Thanks
I solved the issue changing the language in the snippet to "en".
This is the complete request if someone needs it.
body = {
:snippet => {
:videoId => videoId,
:language => "en",
:name => "English"
}
}
captions_insert_response = client.execute(
:api_method => youtube.captions.insert,
:body_object => body,
:media => Google::APIClient::UploadIO.new(captions_file, 'text/xml'),
:parameters => {
'uploadType' => 'multipart',
:part => body.keys.join(',')
}
)

Why am I getting this 'no implicit conversion of Hash into String' when mocking Stripe with WebMock

I'm trying to mock Stripe like this:
stub_request(:post, "https://api.stripe.com/v1/tokens").with(
:body => {"card" => {"number" => "4242424242424242", "exp_month"=> "12", "exp_year" => "2018", "cvc" => "123"}}
).
to_return(:status => 200, :headers => {}, :body => {
"id" => "tok_14CgP22eZvKYlo2CkgJ6ymLE",
"livemode" => false,
"created" => 1404517660,
"used" => false,
"object" => "token",
"type" => "card",
"card" => {
"id" => "card_14CgP22eZvKYlo2CcdUNvicW",
"object" => "card",
"last4" => "4242",
"brand" => "Visa",
"funding" => "credit",
"exp_month" => 12,
"exp_year" => 2018,
"fingerprint" => "Xt5EWLLDS7FJjR1c",
"country" => "US"
}
})
I am getting a no implicit conversion of Hash into String error when I call:
token = Stripe::Token.create(:card => {
:number => params["number"],
:exp_month => params["expiry_month"],
:exp_year => params["expiry_year"],
:cvc => params["cvc"]})
It's because of the hash in body in to_return, but I don't know how to avoid the error.
If I add .to_s to the hash, I get:
Invalid response object from API: "{\"id\"=>\"tok_14CgP22eZvKYlo2CkgJ6ymLE\", \"livemode\"=>false, \"created\"=>1404517660, \"used\"=>false, \"object\"=>\"token\", \"type\"=>\"card\", \"card\"=>{\"id\"=>\"card_14CgP22eZvKYlo2CcdUNvicW\", \"object\"=>\"card\", \"last4\"=>\"4242\", \"brand\"=>\"Visa\", \"funding\"=>\"credit\", \"exp_month\"=>12, \"exp_year\"=>2018, \"fingerprint\"=>\"Xt5EWLLDS7FJjR1c\", \"country\"=>\"US\"}}" (HTTP response code was 200)
If I add a .to_json to the end, Stripe::Token passes but I get a stack error too deep error when I try to use the resulting token in any way.
What do you recommend?
It could be that your stubbing is not returning correctly. It may help to make your stubbing a little less specific. For example:
body = {
"id" => "tok_14CgP22eZvKYlo2CkgJ6ymLE",
"livemode" => false
# snip...
}
stub_request(:post, "https://api.stripe.com/v1/tokens")
.to_return(:status => 200, :body => body.to_json)
However, it's difficult to know exactly what errors are being thrown, so I can only give vague ideas which may help. What error does calling token give you?

Can't get value from nested pair in Omniauth hash.

I'll try to keep this simple, my previous wording was maybe a bit too verbose:
Here is the example Omniauth hash: https://github.com/mkdynamic/omniauth-facebook
I can access and save some values from this but not others. The field is writable, so I know its just my syntax (beginner, sorry!)
{
:provider => 'facebook',
:uid => '1234567',
:info => {
:nickname => 'jbloggs',
:email => 'joe#bloggs.com',
:name => 'Joe Bloggs',
:first_name => 'Joe',
:last_name => 'Bloggs',
:image => 'http://graph.facebook.com/1234567/picture?type=square',
:urls => { :Facebook => 'http://www.facebook.com/jbloggs' },
:location => 'Palo Alto, California',
:verified => true
},
:credentials => {
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
:expires_at => 1321747205, # when the access token expires (it always will)
:expires => true # this will always be true
},
:extra => {
:raw_info => {
:id => '1234567',
:name => 'Joe Bloggs',
:first_name => 'Joe',
:last_name => 'Bloggs',
:link => 'http://www.facebook.com/jbloggs',
:username => 'jbloggs',
:location => { :id => '123456789', :name => 'Palo Alto, California' },
:gender => 'male',
:email => 'joe#bloggs.com',
:timezone => -8,
:locale => 'en_US',
:verified => true,
:updated_time => '2011-11-11T06:21:03+0000'
}
}
}
I can do this to get gender and save it.
location:auth.extra.raw_info["gender"]
Obviously though I dont want to save gender to location. I want to get "Palo Alto" and save it. But this doesn't work.
location.auth.extra.raw_info["location"]["name"]
What am I doing wrong? When I try it in console, I'm able to get the value.
try this
location.auth.extra.raw_info.location.name
or this
location.auth.extra.raw_info[:location][:name]
Yeah, what you suggested was what I was trying...and it turns out we were right but FB had changed how that hash was set up so it wasn't working. Lesson learned: subscribe FB's notifications next time :)

Resources