Ruby add_item for eBay - ruby-on-rails

I am attempting to write a ruby on rails app that posts an item to eBay. Cody Fauser/Garry Tan have a gem called ebayApi which is built on top of the ebay gem. When I attempt to post an item, I am getting an error back from ebay that says the condition ID is required for this category. I have found a category that does not require the condition, and I can post to that category. Searching through the eBay API documentation, I have found a tag conditionID under the "item" class. However, in the documentation for ebayAPI, there is no such tag. Looking back at the ebay API documentation, there is an older way to specify condition, using lookup_attributes. I have noted that the return xml is coming in API version 745, and Garry Gan's updated of the ruby interface is running version 609. I have tried using the lookup, and seem to get the same error (condition required). I am using the following code to specify the item:
#ebay = Ebay::Api.new :auth_token => #seller.ebay_token
item = Ebay::Types::Item.new( :primary_category => Ebay::Types::Category.new(:category_id => #ebayTemplate.categoryID),
:title => #ebayTemplate.name,
:description => #ebayTemplate.description,
:location => #ebayTemplate.location,
:start_price => Money.new((#ebayTemplate.startPrice*100).to_d, #ebayTemplate.currency),
:quantity => 1,
:listing_duration => #ebayTemplate.listingDuration,
:country => #ebayTemplate.country,
:currency => #ebayTemplate.currency,
:payment_methods => ['VisaMC', 'PayPal'],
:paypal_email_address => '********#gmail.com',
:dispatch_time_max => 3,
:lookup_attributes => [Ebay::Types::LookupAttribute.new( :name => "Condition", :value => "New")],
# :attribute_sets => [
# Ebay::Types::AttributeSet.new(
# :attribute_set_id => 2919,
# :attributes => [
# Ebay::Types::Attribute.new(
# :attribute_id => 10244,
# :values => [ Ebay::Types::Val.new(:value_id => 10425) ]
# )
# ]
# )
# ],
:shipping_details => Ebay::Types::ShippingDetails.new(
:shipping_service_options => [
# ShippingServiceOptions.new(
# :shipping_service_priority => 2, # Display priority in the listing
# :shipping_service => 'UPSNextDay',
# :shipping_service_cost => Money.new(1000, 'USD'),
# :shipping_surcharge => Money.new(299, 'USD')
# ),
Ebay::Types::ShippingServiceOptions.new(
:shipping_service_priority => 1, # Display priority in the listing
:shipping_service => #ebayTemplate.shipSvc,
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_surcharge => Money.new((#ebayTemplate.shipSurcharge*100).to_d, #ebayTemplate.currency)
)
],
:international_shipping_service_options => [
Ebay::Types::InternationalShippingServiceOptions.new(
:shipping_service => 'USPSPriorityMailInternational',
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_service_priority => 2,
:ship_to_location => #ebayTemplate.shipToLocation
)
]
),
:return_policy => Ebay::Types::ReturnPolicy.new (
:description => 'this product for suckers only!',
:returns_accepted_option => 'ReturnsAccepted'
)
#:condition_id => 1000
)
#response = #ebay.add_item(:item => item)
As you can see, it is just a mutation of the example given by Cody Fauser. The condition_id at the bottom will bring up an error as there is no such attribute. It seems to me there is no facility for this in the gem since the requirement came into existence after the gem was created. I have not been able to find any other gems to connect with ebay. I have also noticed, there are very little complaints about this even though people are still downloading the gem (10 people downloaded it today). I think there are quite a number of people writing for ebay. Is there a key word I am missing to specify the condition? A work around that people have been using? Another gem I have missed?

There is an existing item_conditions_codes.rb in the gem's type directory and only has two values New and Used. Guess you could add more values in there. However still needs mapping to ID's per the updating (and changed from Attributes) method
You have to modify in the gem library in .. ruby/1.8/gems/ebayapi-0.12.0/lib/ebay/types/item.rb
and add the following new lines
# added to allow ConditionID to be pushed into XML
numeric_node :condition_id, 'ConditionID', :optional => true
then in your ruby ebay code use the following convention
:condition_id => 1500,
At least that seems to work for me right now.

Related

How do I access "request" and "session" objects from within my rspec tests?

I have a Rails 4.2 application that does different business depending on host name. I know this practice is frowned upon in certain circles but I managed to get the same code base working on about 400 websites, the amount of time|cpu|ram|db|money|squirrels saved is tremendous.
Eg:
For www.example.com for user john#doe.com it might show Product 1 with a $5000 price tag;
For www.blah.com for all usrs it might show Product 1 with a $123 price tag. And a shipping fee of $400.
This is all based on host name and a number of variables stored into session when users visit and/or log in to the website.
I'd like to write a bunch of specs to test various aspects of the application but I need to be able to set the request.host, format and some things in the session.
How do I get this done?
Later edit:
I managed to do a find and replace through the source code and get the session/request access done from within some helper methods. Now I can stub within my specs as follows:
allow_any_instance_of(ApplicationHelper).to receive(:detect_user_info_by_ip).with("ip").and_return( { :provider => "dummy", :ip => "127.0.0.1", :lat => 1.0, :latitude => 1.0, :lon => 2.1, :long => 2.1, :longitude => 2.1, :regi
on => "EU", :country => "GB", :city => "Testville", :country_iso2 => "GB", :success => true} )
allow_any_instance_of(ApplicationHelper).to receive(:detect_user_info_by_ip).and_return( { :provider => "dummy", :ip => "127.0.0.1", :lat => 1.0, :latitude => 1.0, :lon => 2.1, :long => 2.1, :longitude => 2.1, :region => "EU",
:country => "GB", :city => "Testville", :country_iso2 => "GB", :success => true} )
Bottom line is: easier to refactor and stub than access the request and session objects from within specs.

How to distinguish between Rails and Rake at the initializers level?

Whether I execute rails or rake, the code present in the initializers folder will be executed. What I want to do is to make sure that the code in a given initializer file doesn't get fired up when running a rake task (hence only when Rails server or console are launched).
For example, I'd like to be able to do something like (in config/initializers/blabla.rb):
do_something # code always executed
unless ENV['rake']
something_when_not_rake # code executed only if rails server or console
end
do_something_more # more code always executed
I've been looking into the ENV variable to see what's available there but I've seen nothing interesting, here's the content (in the format "key" => "value"):
"rvm_bin_path" => "/Users/lucke84/.rvm/bin"
"GEM_HOME" => "/Users/lucke84/.rvm/gems/ruby-2.2.3"
"SHELL" => "/bin/bash"
"TERM" => "xterm-256color"
"TMPDIR" => "/var/folders/73/q8t0jjrx3zb8zvd072dgq11c0000gn/T/"
"IRBRC" => "/Users/lucke84/.rvm/rubies/ruby-2.2.3/.irbrc"
"Apple_PubSub_Socket_Render" => "/private/tmp/com.apple.launchd.mF5Uh4NPbk/Render"
"MY_RUBY_HOME" => "/Users/lucke84/.rvm/rubies/ruby-2.2.3"
"USER" => "lucke84"
"rvm_stored_umask" => "0022"
"_system_type" => "Darwin"
"rvm_path" => "/Users/lucke84/.rvm"
"SSH_AUTH_SOCK" => "/private/tmp/com.apple.launchd.ryhqrdVtVU/Listeners"
"__CF_USER_TEXT_ENCODING" => "0x1F5:0x0:0x0"
"rvm_prefix" => "/Users/lucke84"
"PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/bin:/Users/lucke84/.rvm/gems/ruby-2.2.3#global/bin:/Users/lucke84/.rvm/rubies/ruby-2.2.3/bin:/Users/lucke84/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/apache-maven/apache-maven-3.3.1/bin"
"rvm_loaded_flag" => "1"
"PWD" => "/Users/lucke84/projects/website"
"JAVA_HOME" => "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"
"XPC_FLAGS" => "0x0"
"_system_arch" => "x86_64"
"_system_version" => "10.11"
"XPC_SERVICE_NAME" => "0"
"rvm_version" => "1.26.11 (latest)"
"HOME" => "/Users/lucke84"
"SHLVL" => "1"
"rvm_ruby_string" => "ruby-2.2.3"
"LOGNAME" => "lucke84"
"LC_CTYPE" => "en_US.UTF-8"
"GEM_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3:/Users/lucke84/.rvm/gems/ruby-2.2.3#global"
"rvm_delete_flag" => "0"
"RUBY_VERSION" => "ruby-2.2.3"
"_system_name" => "OSX"
"rvm_user_install_flag" => "1"
"BUNDLE_GEMFILE" => "/Users/lucke84/projects/website/Gemfile"
"_ORIGINAL_GEM_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3:/Users/lucke84/.rvm/gems/ruby-2.2.3#global"
"BUNDLE_BIN_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/bundler-1.10.6/bin/bundle"
"RUBYOPT" => "-rbundler/setup"
"RUBYLIB" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/bundler-1.10.6/lib"
"MANPATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/unicorn-5.0.1/man"
I cannot find a built-in environment key/value to programmatically determine who is triggering the command. Maybe one of you can shed some light on this topic for me?
Further details:
this cannot be an environment-dependent check, it should work for development as well as for production (or whatever the environment)
I would like to avoid to specify a custom parameter (i.e. bin/rake my:task skip_initializer=true), as what I'm trying to do is to skip that initializer's executions for all rake tasks
running Rails 4.2.x at the moment
Thanks in advance for your help!

Requiring apt::source as a dependency gives a syntax error

I need to add the docker source list to apt before installing docker.
I have
apt::source { 'debian-jessie':
comment => 'This is the docker Debian jessie mirror',
location => 'http://apt.dockerproject.org/repo',
release => 'debian-jessie',
repos => 'main',
key_content => '58118E89F3A912897C070ADBF76221572C52609D',
key_server => 'keyserver.ubuntu.com',
ensure => present,
include_src => false,
include_deb => true,
}
which works, and also
package {'docker-engine':
ensure => present,
before => Class['docker'],
}
which works only after a second run (I use vagrant provision, but that's not relevant to the problem).
What I would like is making the whole thing work at the first provisioning by instructing puppet to execute apt::source before docker-engine, however adding it in require is not a valid syntax:
package {'docker-engine':
ensure => present,
before => Class['docker'],
require => [
Apt::source['debian-jessie'],
]
}
How to specify this dependency?
The rest of the file looks like this:
class { 'docker':
dns => '192.168.1.1',
manage_package => false,
use_upstream_package_source=> false,
# service_name => 'docker',
docker_command => 'docker',
package_name => 'docker-engine',
service_enable => true,
service_state => 'running',
extra_parameters => ["--insecure-registry=192.168.1.0/24"],
}
include 'docker'
file { "/lib/systemd/system/docker.service":
notify => Service["docker"],
ensure => present,
owner => "root",
group => "root",
mode => 0600,
source =>"puppet:///modules/docker/etc/systemd/system/docker.service"
} ~> Exec['systemctl-daemon-reload']
Capitalize word source
require => Apt::Source['debian-jessie']
Puppet documentation states:
The general form of a resource reference is:
The resource type, capitalized (every segment must be capitalized if
the resource type includes a namespace separator [::])
An opening square bracket
The title of the resource as a string, or a comma-separated list of titles
A closing square bracket

HBase via MassiveRecord in Ruby is causing an abort

When using MassiveRecord over thrift to save a record into HBase, I get a strange "abort" error.
Here is some code that will reproduce the error on Mac OS X, with hbase (0.92.0 and 0.94.0) install via homebrew.
require 'massive_record'
MassiveRecord::ORM::Base.connection_configuration = { :host => 'hbase' }
class Woot < MassiveRecord::ORM::Table
default_scope select(:data)
column_family :data do
field :name, :string
end
end
woot = Woot.new( :name => 'rawr' )
woot.save
This always causes the process to halt, leaving the message
[1] 8756 abort ruby massive_woot.rb
Retrieving works just fine, but I can't seem to save the records.
Here is what the schema looks like:
>> describe 'woots'
DESCRIPTION ENABLED
{NAME => 'woots', FAMILIES => [{NAME => 'data', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', C true
OMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCA
CHE => 'true'}]}
1 row(s) in 0.0190 seconds
This turned out to be a versioning issue. MassiveRecord v0.2.2 depends on thrift 0.6.0 (specified by an "= 0.6.0" version in the Gemfile).
I solved this for now by pulling off the "develop" branch of MassiveRecord from github.

Pre-filling first and last name in Paypal setExpressCheckout using ActiveMerchant

I'm trying to get Paypal SetExpressCheckout operation to add first and last name for billing. I'm using ActiveMerchant. I'm seeing the address field pre-populated (street, state, city,zip-code) but nothing else.
#### gateway ######
gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(:login => 'login',:password => 'pass',:signature => 'sig')
### options ######
#options = Hash.new
#options.merge!(:ip => '127.0.0.1')
#options.merge!(:return_url => '127.0.0.1')
#options.merge!(:return_url => 'http://www.google.com')
#options.merge!(:cancel_return_url => 'http://www.google.com')
#options.merge!(:name => 'name')
#options.merge!(:description => 'description')
#options.merge!(:max_amount => 5000)
#options.merge!(:solution_type => 'Sole')
#options.merge!(:no_shipping => 1)
#options.merge!(:address_override => 1)
### build address
#address = Hash.new
#address.merge!(:name => "Joe User")
#address.merge!(:address1 => "111 ABCD EFG")
#address.merge!(:address2 => nil)
#address.merge!(:city => "Fremont")
#address.merge!(:state => "CA")
#address.merge!(:country => "US")
#address.merge!(:phone => "408-111-2222")
#options.merge!(:address => #address)
setup_response = gateway.setup_purchase(5000, #options)
redirect_to gateway.redirect_url_for(setup_response.token)
On the resultant page, I'm not seeing the name pre-filled for billing.
What am I doing wrong?
Thanks
I had the same issue as you did. After some research I came to the conclusion that this is a bug in ActiveMerchant. Please see the issue that I filed. It includes an explanation of how I patched my code to make phone number and names work:
https://github.com/Shopify/active_merchant/issues/161

Resources