The following ruby code automatically creates pages inside VoodooPad and adds meta tags to each page.
vp = app("VoodooPad.app")
doc = vp.open vpdoc
page_names = [#name]
if self.class.to_s.match('Stake::Stack')
# Create the release notes page. Only run on parent stack
notes = "#{#name} Release Notes"
page_names.push notes
doc.remove :with_name => notes
doc.create :new => :page, :with_name => notes, :with_content => self.release_notes
end
# Create the settings page
settings = "#{#name} Settings"
page_names.push settings
doc.remove :with_name => settings
doc.create :new => :page, :with_name => settings, :with_content => self.to_md
page_names.each do |page_name|
# Add the meta tags to the product page
page = doc.pages[page_name]
puts page_name
page.remove_meta_record :with_key => "description"
page.remove_meta_record :with_key => "url"
page.remove_meta_record :with_key => "name"
page.remove_meta_record :with_key => "image"
page.remove_meta_record :with_key => "version"
page.remove_meta_record :with_key => "stacks_version"
page.add_meta_record :with_value => {'version' => #version_str}
page.add_meta_record :with_value => {'stacks_version' => #stacks_version}
page.add_meta_record :with_value => {'subtitle' => #subtitle}
page.add_meta_record :with_value => {'url' => #info_url}
page.add_meta_record :with_value => {'image' => #basename + '#128.png'}
page.add_meta_record :with_value => {'name' => #name}
end
In the each block, the same meta tags are getting added to 3 pages. However, the tags are only getting added to 2 of the 3 pages. If we take the name of "Badges" as an example, here are my page names.
Badges
Badges Release Notes
Badges Settings
No matter the order of the array, the "Badges" page always gets the properly tagged. However, for the other 2 pages, which ever is processed first works. The other does not.
I thought maybe it was spaces in the page names. However, that does not matter. I get the same behavior. If you notice the code also dynamically creates both of these pages properly.
I have also tried adding a sleep, thinking it may be a timing thing. Nope.
I am stuck. Help.
I figured it out. The page that I was adding tags to could not be the currently active page.
vp = app("VoodooPad.app")
doc = vp.open vpdoc
page_names = Array.new
if self.class.to_s.match('Stake::Stack')
# Only the parent stack has a main page
page_names.push #name
# Create the release notes page. Only run on parent stack
notes = "#{#name} Release Notes"
page_names.push notes
doc.remove :with_name => notes
doc.create :new => :page, :with_name => notes, :with_content => self.release_notes
end
# Create the settings page
settings = "#{#name} Settings"
page_names.push settings
doc.remove :with_name => settings
doc.create :new => :page, :with_name => settings, :with_content => self.to_md
# Have to open to different page to ensure its not open when I add meta tags.
doc.open_page :with_name => 'index'
page_names.each do |page_name|
# Add the meta tags to the product page
page = doc.pages[page_name]
puts page_name
page.remove_meta_record :with_key => "description"
page.remove_meta_record :with_key => "url"
page.remove_meta_record :with_key => "name"
page.remove_meta_record :with_key => "image"
page.remove_meta_record :with_key => "version"
page.remove_meta_record :with_key => "stacks_version"
page.add_meta_record :with_value => {'version' => #version_str}
page.add_meta_record :with_value => {'stacks_version' => #stacks_version}
page.add_meta_record :with_value => {'subtitle' => #subtitle}
page.add_meta_record :with_value => {'url' => #info_url}
page.add_meta_record :with_value => {'image' => "#{#basename}#128.png".downcase}
page.add_meta_record :with_value => {'name' => #name}
# Open current page to ensure next page is not open or else cannot add tags
doc.open_page :with_name => page_name
end
Related
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?
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(',')
}
)
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 :)
I am trying to call the catalog_product_link.list API method using Savon. However, I keep receiving the error Error cannot find parameter.
Here is what I am using, though I have tried several variations of the call and still cannot get it to go through correctly:
client = Savon.client(wsdl: 'http://localhost/index.php/api/soap/?wsdl')
response = client.call(:login){message(username: 'user', apiKey: 'key')}
session = response.body[:login_response][:login_return]
#These all do not work
client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :type => 'up_sell', :productId => '166')}
client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :type => 'up_sell', :product => '166')}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :args => {:type => 'up_sell', :product => '166'})}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :args => {:type => 'up_sell', :productId => '166'})}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :arguments => {:type => 'up_sell', :product => '166'})}
Is there a different way to format to get this to work?
UPDATE: If I try removing the type parameter, it gives the error Given invalid link type, so it appears it does not like something about multiple parameters.
response = client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :product => '166')}
I was able to get this to work using Builder:
class ServiceRequest
def initialize(session, type, product)
#session = session
#type = type
#product = product
end
def to_s
builder = Builder::XmlMarkup.new()
builder.instruct!(:xml, encoding: "UTF-8")
builder.tag!(
"env:Envelope",
"xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:ns1" => "urn:Magento",
"xmlns:ns2" => "http://xml.apache.org/xml-soap",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
) do |envelope|
envelope.tag!("env:Body") do |body|
body.tag!("ns1:call") do |call|
builder.sessionId(#session, "xsi:type" => "xsd:string")
builder.resourcePath("catalog_product_link.list", "xsi:type" => "xsd:string")
builder.args("xsi:type" => "ns2:Map") do |args|
args.item do |item|
item.key("type", "xsi:type" => "xsd:string")
item.value(#type, "xsi:type" => "xsd:string")
end
args.item do |item|
item.key("product", "xsi:type" => "xsd:string")
item.value(#product, "xsi:type" => "xsd:string")
end
end
end
end
end
builder.target!
end
end
client.call(:call, xml: ServiceRequest.new(session, 'up_sell', '166').to_s)
Thanks to #rubiii for the direction.
I'm getting =0A inside my emails where there should be a line break.
#article = DB[:posts][:nodeview_id => view, :nodeview => 'article']
Pony.mail(:html_body => #article[:content], :reply_to => #email, :subject => "New article #{#article[:title]}", :headers => { "X-MC-Tags" => "feedback" } )
And ##article[:content]} in this context, is
apples
bananas
inside the database, no \n or <br> tags.
Here's how Pony is configured.
Pony.options = { :from => 'Compesh <donotreply#compesh.com>', :to => 'blahblahblah#emails.com',
:via => :smtp, :via_options => {
:address => 'smtp.mandrillapp.com', :port => '587',
:user_name => 'XXX', :password => 'XXXXXX'
},
:headers => { "X-MC-AutoText" => "yes" }, :charset => 'utf-8'
}
But in my emails I get
apples=0Abananas
Pony doesn't let me choose the content type, I don't think.
I managed to fix this by converting newlines to a <br> tag. It turns out it had nothing to do with the content type or encoding of the email at a..
mystring.gsub(/(?:\n\r?|\r\n?)/, '<br>')
This specially general regex function, has a way of covering DOS, *NIX, Mac and accidental invalid line endings.