I'm facing a problem while trying to extract fields of foursquare2 gem response. Here's my code:
require 'foursquare2'
client = Foursquare2::Client.new(:client_id => 'XYZ', :client_secret => 'XYZ')
tips = client.venue_tips('4d169843b15cb1f7f4c4ae21')
And then I got the result:
#<Hashie::Mash count=8 items=[#<Hashie::Mash canonicalUrl="https://foursquare.com/item/4f689747e4b04ab624cce6d3" createdAt=1332254535 done=#<Hashie::Mash count=1> id="4f689747e4b04ab624cce6d3" lang="pt" likes=#<Hashie::Mash count=2 groups=[#<Hashie::Mash count=2 items=[#<Hashie::Mash bio="" contact=#<Hashie::Mash> firstName="Pedro" gender="male" homeCity="Recife, Brasil" id="19761425" lastName="T." photo="https://is1.4sqi.net/userpix_thumbs/G5R14BT031K2B2AX.jpg" tips=#<Hashie::Mash count=25>>, #<Hashie::Mash bio="" contact=#<Hashie::Mash> firstName="Nat\u00E1lia" gender="female" homeCity="Recife, Brasil" id="12706383" lastName="S."
photo="https://is0.4sqi.net/userpix_thumbs/UF0Q0OZFWNQLXRFG.jpg" tips=#<Hashie::Mash count=1>>] type="others">] summary="2 likes"> text="Nova padaria com bons produtos, destaque para as formadas de p\u00E3o \u00E0 tarde."
I'd like to have something as tips.firstName to get these values, but it doesn't work. Should I prefer the REST API?!
Thank you in advance, guys.
Edited after comments
The solution I did following the suggestion provided:
tips.groups[0].items.each{|i| puts i.firstName}
But it's not working. I just got the error: data_scraping_fq.rb:16:in <main>': undefined method[]' for nil:NilClass (NoMethodError)
tips.firstName won't work when you're using the venues/tips endpoint. Take a look at the JSON response when you use the Foursquare API explorer and you'll see that to get the tip submitter's first name, you need to look at `tips.items
Related
Every time I try and publish a product with AddFixedPriceItem with the Site ID set to Australia (15) I get the error response:
:errors=>{:short_message=>"Input data is invalid.", :long_message=>"Input data for tag is invalid or missing. Please check API documentation."
I tried every variation of the site ID ("AU", "Australia", 15, "15") and when i switch it to the US site ID (0) everything works perfectly. Is there something that I'm doing wrong?
Im using my own customised version of EbayR (because it didn't parse the xml correctly)
Anyway here is the full raw SOAP request:
Headers:
{
'X-EBAY-API-COMPATIBILITY-LEVEL' => #compatability_level.to_s, # => 837
'X-EBAY-API-DEV-NAME' => dev_id.to_s,
'X-EBAY-API-APP-NAME' => app_id.to_s,
'X-EBAY-API-CERT-NAME' => cert_id.to_s,
'X-EBAY-API-CALL-NAME' => #command.to_s,
'X-EBAY-API-SITEID' => #site_id.to_s, # => which is 15
'Content-Type' => 'text/xml'
}
the full body request is:
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>....</eBayAuthToken>
</RequesterCredentials>
<Item>
<Title>dssddsheykduhfid</Title>
<ListingDuration>GTC</ListingDuration>
<ListingType>FixedPriceItem</ListingType>
<Description>This is another test description with image</Description>
<PrimaryCategory>
<CategoryID>57989</CategoryID>
</PrimaryCategory>
<SKU>dfiuhdssdsdfggfmeesddffdeseddfda</SKU>
<InventoryTrackingMethod>SKU</InventoryTrackingMethod>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>payments-facilitator#logicsaas.com</PayPalEmailAddress>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
<ConditionID>1000</ConditionID>
<Country>AU</Country>
<Currency>AUD</Currency>
<DispatchTimeMax>4</DispatchTimeMax>
<PostalCode>3194</PostalCode>
<ReturnPolicy>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<Description>What! you dont want the product! .... ok</Description>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<PictureDetails>
<PictureURL>http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg</PictureURL>
</PictureDetails>
<ShippingDetails>
<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>
<ShippingService>AU_eBayAusPost3kgFlatRateSatchel</ShippingService>
<ShippingServiceCost>10</ShippingServiceCost>
</ShippingServiceOptions>
</ShippingDetails>
<Site>15</Site>
<Variations>
<VariationSpecificsSet>
<NameValueList>
<Name>Size</Name>
<Value>L</Value>
<Value>S</Value>
</NameValueList>
<NameValueList>
<Name>Color</Name>
<Value>Red</Value>
<Value>Blue</Value>
</NameValueList>
</VariationSpecificsSet>
<Variation>
<SKU>dfiuhdssdsdfggfmeesddffdeseddfdaOMG454fgfgfg</SKU>
<StartPrice>100.99</StartPrice>
<Quantity>1</Quantity>
<VariationSpecifics>
<NameValueList>
<Name>Size</Name>
<Value>L</Value>
</NameValueList>
<NameValueList>
<Name>Color</Name>
<Value>Red</Value>
</NameValueList>
</VariationSpecifics>
</Variation>
<Variation>
<SKU>dfiuhdssdsdfggfmeesddffdeseddfdaOMG432325fgfgfg</SKU>
<StartPrice>100.99</StartPrice>
<Quantity>16</Quantity>
<VariationSpecifics>
<NameValueList>
<Name>Size</Name>
<Value>L</Value>
</NameValueList>
<NameValueList>
<Name>Color</Name>
<Value>Blue</Value>
</NameValueList>
</VariationSpecifics>
</Variation>
</Variations>
</Item>
Also I bit the bullet and payed the 75 dollars for technical support, If I don't get a response here I'll paste the response from them for all to see.
Cool, so it seems like this was an ebay issue. They are trying to fix it at the moment. But they responded with a work around:
Hello Avin ,
Thank you for reporting this issue. I can reproduce the problem and I have forwarded this to our engineering team for further investigation. We will keep the ticket open in "Waiting-BugFix" status.
Actually SiteID is not a mandatory field. SiteID will be taken from the header if you don't pass it. As a workaround, please omit the field and continue listing.
Please let me know if you have any questions.
Best Regards,
eBay Developer Support
I'm trying to make what appears to be a pretty straight forward SOAP request, one that works in SoapUI but when I execute my Ruby code, I get a 'raise_soap_and_http_errors!' Exception executing request.
Here's the code - the document referenced in wsdl_path works in SOAPUI to make the authenticate request.
require 'savon'
wsdl_path = 'XXXX_soap_interface.wsdl'
client = Savon.client(
:wsdl => wsdl_path,
:ssl_verify_mode => :none,
:raise_errors => true, # false if you don't want to see exceptions
pretty_print_xml: true)
response = client.call(
:authenticate,
message: {:partnerName => 'XXXX', :userName => 'xxxxxx', :password => 'xxxxx'}
)
puts response
The error I get back is:
savon/response.rb:85:in `raise_soap_and_http_errors!': (SOAP-
ENV:Server) Exception executing request (Savon::SOAPFault)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/response.rb:14:in `initialize'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:64:in `new'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:64:in `create_response'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:55:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/client.rb:36:in `call'
from xxx_soap.rb:15:in `<main>'
I'm running Ruby 1.9, anyone have any ideas on what would make this work?
edit: The wsdl_path variable, when used to create the Savon client, works. I'm able to create the client and also execute client.operations and successfully get back the operations from the SOAP service. Only the request is failing.
edit: After adding the helpful logging code from below, I am getting this back:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:common="urn:xxx-com:cloud:common"
xmlns:finsvc="urn:xxx-com:cloud:finsvc"
xmlns:finsvc-13-6-0="urn:xxx-com:cloud:finsvc:13.6.0">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Exception executing request</faultstring>
<detail>
<operationResult>
<errorCode>101</errorCode>
<errorMessage>SOAP error 44 (SOAP 1.1 fault: SOAP-ENV:Client [no subcode] "Validation constraint violation: occurrence v
iolation in element 'userName'" Detail: [no detail] )</errorMessage>
</operationResult>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
No matter what order I put the parameters in or if I use camelcase or not, the first parameter specified in message throws the above error.
Switch on logging with
client = Savon.client(
...
log: true,
loglevel: :debug,
pretty_print_xml: true)
and share the output if you can't find the problem.
If the problem still exists then you should go the standard way:
Get SoapUI
create a valid call which you can execute successfully
based on that - write a Ruby script (not Ruby on Rails!!) which creates a valid request
integrate that code into your Rails (or whatever project).
So this all turned out to be issues in the wsdl document where fields that were required were not stated as so, but the response from the service did not reveal this.
wsdl_path should be a full URL, like http://domain.name/.../soap.wsdl.
I was using the following code snippet, which was working, to fetch the JSON response from the Spotify oEmbed API.
I was doing this:
response = JSON.parse(open("https://embed.spotify.com/oembed/?url=http://open.spotify.com/album/5Mxj65mCzxUjDkoqz7JXPJ").read)
But now, this stopped working because:
2.0.0p247 :017 > open("https://embed.spotify.com/oembed/?url=http://open.spotify.com/album/5Mxj65mCzxUjDkoqz7JXPJ").read
=> ""
But, using cURL, I get:
$curl https://embed.spotify.com/oembed/\?url\=http://open.spotify.com/album/5Mxj65mCzxUjDkoqz7JXPJ
{"provider_url":"https:\/\/www.spotify.com","version":"1.0","thumbnail_width":300,"height":380,"thumbnail_height":300,"title":"Illum Sphere - 13. Embryonic","width":300,"thumbnail_url":"https:\/\/d3rt1990lpmkn.cloudfront.net\/cover\/d4f5d8624752eeae3dc8bc3d58e2155d095181c1","provider_name":"Spotify","type":"rich","html":"<iframe src=\"https:\/\/embed.spotify.com\/?uri=spotify:album:5Mxj65mCzxUjDkoqz7JXPJ\" width=\"300\" height=\"380\" frameborder=\"0\" allowtransparency=\"true\"><\/iframe>"}
Any advice?
Try passing the User-Agent:
require 'open-uri'
puts open("https://embed.spotify.com/oembed/?url=http://open.spotify.com/album/5Mxj65mCzxUjDkoqz7JXPJ", "User-Agent" => "Ruby/#{RUBY_VERSION}").read
Result:
{"provider_url":"https:\/\/www.spotify.com","version":"1.0","thumbnail_width":300,"height":380,"thumbnail_height":300,"title":"
Illum Sphere - 13. Embryonic","width":300,"thumbnail_url":"https:\/\/d3rt1990lpmkn.cloudfront.net\/cover\/d4f5d8624752eeae3dc8b
c3d58e2155d095181c1","provider_name":"Spotify","type":"rich","html":"<iframe src=\"https:\/\/embed.spotify.com\/?uri=spotify:al
bum:5Mxj65mCzxUjDkoqz7JXPJ\" width=\"300\" height=\"380\" frameborder=\"0\" allowtransparency=\"true\"><\/iframe>"}
I am new to ruby/watir and am getting an error when trying to click on a link.
The error is:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-classic/elemen
t.rb:328:in `assert_exists': Unable to locate element, using {:tag_name=>["a"],
:id=>"My Link"} (Watir::Exception::UnknownObjectException)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:474:in `perform_action'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:354:in `click!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-c
lassic/element.rb:157:in `click'
from Login.rb:22:in `<main>'
The link that I am trying to click looks like this:
<TD><DIV id=div style="DISPLAY: inline"><A id=Hyperlink href="javascript:RunFullScreen('myURL')">My Link</A></DIV>
Also, I tried to write out all links on the page using 'puts', but nothing was written out when the script finished
I used this code to write out the links (not sure if this is correct or not):
browser.links.each {|link| puts link.attribute_value("text") if link.visible?}
The error says tat you tried to find an object with the following properties: {:tag_name=>["a"], :id=>"My Link"}, but you have show us HTML code with A id=Hyperlink. So to find out that HTML you need to specify properly its attributes:
#b.element :tag_name => 'a', :id => 'Hyperlink'
or
#b.a :id => 'Hyperlink'
I have a very basic question, am looking at some rails code similar to following but not able to interpret it, what are the REST urls and corresponding actions inferred from this? Can someone please help understand as I did not find any examples of similar routes.
map.resources :myresources do |item|
item.resources :v, :controller => 'my_controller' do |v|
v.resource :abc
end
end
Thanks in advance!!
This is actually the old routing style.
Now you can just write the code this way:
resources :myresources do
resources :v, :controller => "my_controller" do
resource :abc
end
end
With this code you will get these routes:
myresource_v_abc POST /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#create
new_myresource_v_abc GET /myresources/:myresource_id/v/:v_id/abc/new(.:format) abcs#new
edit_myresource_v_abc GET /myresources/:myresource_id/v/:v_id/abc/edit(.:format) abcs#edit
GET /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#show
PUT /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#update
DELETE /myresources/:myresource_id/v/:v_id/abc(.:format) abcs#destroy
myresource_v_index GET /myresources/:myresource_id/v(.:format) my_controller#index
POST /myresources/:myresource_id/v(.:format) my_controller#create
new_myresource_v GET /myresources/:myresource_id/v/new(.:format) my_controller#new
edit_myresource_v GET /myresources/:myresource_id/v/:id/edit(.:format) my_controller#edit
myresource_v GET /myresources/:myresource_id/v/:id(.:format) my_controller#show
PUT /myresources/:myresource_id/v/:id(.:format) my_controller#update
DELETE /myresources/:myresource_id/v/:id(.:format) my_controller#destroy
myresources GET /myresources(.:format) myresources#index
POST /myresources(.:format) myresources#create
new_myresource GET /myresources/new(.:format) myresources#new
edit_myresource GET /myresources/:id/edit(.:format) myresources#edit
myresource GET /myresources/:id(.:format) myresources#show
PUT /myresources/:id(.:format) myresources#update
DELETE /myresources/:id(.:format) myresources#destroy