Git Product home page Git Product logo

ebayr's Introduction

Ebayr

Ebayr is a small gem which makes it a little easier to use the eBay Trading API with Ruby.

Installation

Add this line to your application's Gemfile:

gem 'ebayr'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ebayr

Ruby versions pre-2.2

Older versions of ruby are no longer supported as of v0.1.0. To use ebayr with Ruby 1.8, try version v0.0.9.

$ gem install ebayr -v '=0.0.9'

You may need to install an earlier version of activesupport in order to make this work (since the dependency i18n does not support 1.8 after version 0.6.11). Your mileage may vary, and you probably should update your Ruby version anyway.

If you would like to use anthing pre Ruby 2.2, then, you can try any of the releases from the v0.0 branch; the latest is v0.0.11

$ gem install ebayr -v '=0.0.11'

Again, YMMV, and the same advice applies.

Usage

To use the eBay Trading API, you'll need a developer keyset. Sign up at http://developer.ebay.com if you haven't already done so.

Next, you'll need to require Ebayr, and tell it to use your keys. You will also need to generate an RUName, and get the key for that. (This is all standard stuff - look at the eBay developer docs for details).

require 'ebayr'

Ebayr.dev_id = "my-dev-id"

# This is only needed if you want to retrieve user tokens
Ebayr.authorization_callback_url = "https://my-site/callback-url"

Ebayr.auth_token = "myverylongebayauthtoken"

Ebayr.app_id = "my-ebay-app-id"

Ebayr.cert_id = "my-ebay-cert-id"

Ebayr.ru_name = "my-ebay-ru-name"

# Set this to true for testing in the eBay Sandbox (but remember to use the
# appropriate keys!). It's true by default.
Ebayr.sandbox = false

Now you're ready to make calls

Ebayr.call(:GeteBayOfficialTime)
session = Ebayr.call(:GetSessionID, :RuName => Ebayr.ru_name)[:SessionID]

To use an authorized user's key, pass in an auth_token parameter

Ebayr.call(:GetOrders, :auth_token => "another-ebay-auth-token")

Use the input array to add to the body of the call

# Adds: "<a>1</a><a><b>1</b><b>2</b></a>" to the ebay request.
args = [{ :a => 1 }, { :a => [{:b => 1 }, { :b => 2 }] }]
Ebayr::Request.new(:Blah, :input => args)

Configuration

Ebayr will look for the following Ruby files, and load them once in order (if they exist) when the module is evaluated:

  1. /etc/ebayr.conf
  2. /usr/local/etc/ebayr.conf
  3. ~/.ebayr.conf
  4. ./.ebayr.conf

You can put configuration code in there (such as the variable setting shown above). The files should be plain old Ruby.

In a Ruby on Rails project, just create a file called config/initializers/ebayr.rb (or something), and put the configuration there. Of course, you should probably not check in these files, if you're using a public repository.

Testing

Status

When running test, you generally won't want to use up your API call-limit too quickly, so it makes sense to stub out calls to the eBay API.

Ebayr test use Fakeweb to mimic the responses from eBay.

require 'ebayr'
require 'test/unit'
require 'fakeweb'

class MyTest < Test::Unit::TestCase
  def setup
    Ebayr.sandbox = true
  end

  # A very contrived example...
  def test_get_ebay_time
    xml = <<-XML
      <GeteBayOfficialTimeResponse>
        <Ack>Success</Ack>
        <Timestamp>blah</Timestamp>
      </GeteBayOfficialTimeResponse>
    XML

    FakeWeb.register_uri(:post, Ebayr.uri, :body => xml)

    time = SomeWrapperThatUsesEbayr.get_ebay_time
    assert_equal 'blah', time
  end
end

class SomeWrapperThatUsesEbayr
  def self.get_ebay_time
    hash = Ebayr.call(:GeteBayOfficialTime)
    hash.timestamp
  end
end

See './test/ebayr_test.rb' for more examples.

You need to remember to include Fakeweb in your Gemfile, or Ebayr will complain.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

Thanks to the great contributing maintainers on GitHub, including:

  • David DeGraw
  • Eric McKenna
  • Jason Schock
  • Laurent Arnoud
  • SpeerJ
  • jogaco

ebayr's People

Contributors

bjjb avatar emckenna avatar gcorbel avatar jasonschock avatar jogaco avatar speerj avatar spk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ebayr's Issues

RuntimeError: entity expansion has grown too large

I get this error for an item with a description with many html entities.

    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/text.rb:398:in `block in unnormalize'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/text.rb:395:in `gsub'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/text.rb:395:in `unnormalize'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/text.rb:252:in `value'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/element.rb:452:in `text'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/element.rb:433:in `has_text?'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/activesupport-4.2.0/lib/active_support/xml_mini/rexml.rb:74:in `merge_texts!'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/activesupport-4.2.0/lib/active_support/xml_mini/rexml.rb:63:in `collapse'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/activesupport-4.2.0/lib/active_support/xml_mini/rexml.rb:48:in `merge_element!'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/activesupport-4.2.0/lib/active_support/xml_mini/rexml.rb:59:in `block in collapse'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/element.rb:902:in `block in each'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/xpath.rb:67:in `each'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/xpath.rb:67:in `each'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/element.rb:902:in `each'
    from /home/my/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rexml/element.rb:393:in `each_element'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/activesupport-4.2.0/lib/active_support/xml_mini/rexml.rb:59:in `collapse'
... 14 levels...
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/ebayr-0.0.9/lib/ebayr/response.rb:10:in `initialize'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/ebayr-0.0.9/lib/ebayr/request.rb:86:in `new'
    from /home/my/.rvm/gems/ruby-2.1.3@project/gems/ebayr-0.0.9/lib/ebayr/request.rb:86:in `send'

Results as Objects

It would be pretty cool if the results automatically turned themselves into clever objects, so that you could go:

Ebayr.call(:GetItem, :ItemID => 1234567890).map(&:name)

A quick start would probably be to turn them (recursively) into OpenStructs.

We ought to ensure that we don't hammer performance on large result sets, though. Would probably help to have some benchmarking built in.

Bump version?

I know it's been a year, but any plans to bump to 0.5.0?

How can I sumbit multi node in a same name?

Like this:

shippings.each do |s|
      :ShippingServiceOptions => {
        :ShippingServicePriority => 1,
        :ShippingService => s.name,
        :ShippingServiceCost => s.cost
      }
 end

obviously if in hash the same key will be overwrite by the latest. How can I solve this problem? Or I should add a dirty hack myself?

listing fails if the title attribute has an ampersand (&) on it.

Hi,

I've been using this gem for the past two years and never had an issue I could not solve,... until now.

I'm trying to create listings where the title has the ampersand character and it fails with the response error message:
nested exception is: \n\torg.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference."

I have tried everything I can think of to escape the "&" but it always fails with the same error.

Here is the title of the listing I've been using to try and sort out the problem:
"Black & Decker Vacuum Cleaner Carpet Upholstery tapestry Tool Attachment"

I have tried all of the following:
title.gsub("&", "&")
title.gsub("&", "&")
title.gsub("&", "%26")

Tried with .encode('utf-8') before the gsub, after the gsub, tried without the encode, etc

Am I missing something obvious here? Any help will be greatly appreciated as I'm running out of ideas.

xml attributes are not returned

If the ebay API returns

<SellingStatus>
      <BidCount>3</BidCount>
      <BidIncrement currencyID="GBP">0.2</BidIncrement>
...

req[:item][:selling_status] will not contain attribute info.

really need a serious xml builder

{"Name"=>"Color", "Value"=>["Black", "Pink", "Yellow", "Blue"]} went in
and
<Name>Color</Name><Value>BlackPinkYellowBlue</Value> went out

which should be
<Name>Color</Name><Value>Black</Value><Value>Pink</Value><Value>Yellow</Value><Value>Blue</Value>

why not try ActiveSupport or something?

Allow more than one instance of the Ebay API connection

Use cases:

  • Running a test with two different Ebay users (e.g. buyer and seller)
  • Connecting to sandbox and production system simultaneously. That is necessary when in a test/dev system you want to work with category suggestions: Category suggestions work only in production system, not in the sandbox. So, this call may just as well always connect to the production system, no matter whether it is test, dev or production.

The new usage pattern may then look like this:

ebay1 = Ebayr::API.new(configuration_hash_from_file)
ebay.call(:GetSuggestedCategories, options_1)

ebay2 = Ebayr::API.new(another_configuration_hash_from_file)
ebay.call(:GetItem, options_2)

allthewhile maintaining backward compatibility…

Not able to add multiple media attachments

Not able to add multiple media attachments for AddMemberMessageRTQ api call...Below is my api call

Ebayr.call(:AddMemberMessageRTQ,:ItemID => "******" ,:MemberMessage => {:Body => Test, :MessageMedia => {:MediaName => "Test1",:MediaURL => "URL1"}, :MessageMedia => {:MediaName => "Test2",:MediaURL => "URL2"}, :ParentMessageID=> "ID" , :RecipientID=> "ID" })

Paginate results

Results from the trading API need to handle pagination when the number of results exceeds 200.

See here to get started.

Not Able to add PictureURL for AddFixedPriceItem

In this function requires like this
"PictureDetails
GalleryDuration:token
GalleryType: GalleryTypeCodeType
GalleryURL:anyURI
PhotoDisplay: PhotoDisplayCodeType
PictureSource: PictureSourceCodeType
anyPictureURL1
anyPictureURL1
anyPictureURL1

"
How can I add this PicturURL on calling apis option?

Support ActiveSupport v5.x

I'm very new to eBay API so probably I've missed out any helpful information about GetSessionID, not sure if it's related to this gem but I'm trying every possible way.

In my Rails app the current code tries to get a session ID before appending to the authorization URL so that the Rails app can get an auth token for ebay store access, but it didn't work now even though I've set to production environment. I'm trying to call GetSessionID from rails console just to make sure session ID is available before I redirect users to ebay in my controller.

session = Ebayr.call(:GetSessionID, :RuName => Ebayr.ru_name)
=> {:xmlns=>"urn:ebay:apis:eBLBaseComponents",
 :timestamp=>"2017-09-18T06:22:48.336Z",
 :ack=>"Failure",
 :errors=>
  {:short_message=>"Auth token is invalid.",
   :long_message=>"Validation of the authentication token in API request failed.",
   :error_code=>"931",
   :severity_code=>"Error",
   :error_classification=>"RequestError"},
 :version=>"1031",
 :build=>"E1031_CORE_API_18535225_R1"}

I've double checked my app id, dev id, cert id are all set and Ebayr.sandbox is set to false, the only thing I didn't set is the auth_token because new users don't have any before authorizing my app, but if I set an auth_token(of other authorized users) before calling GetSessionID it actually works. Any idea on this? Thanks in advance.

Not able to add attributes on tags

As you can see in the doc some tag needs attributes. For example, <Total currencyID="CurrencyCodeType"> AmountType (double) </Total>.

I tried to do this :

Ebayr::Request.new(:AddOrder, input: [{ Order: { CreatingUserRole: 'Buyer', 'Total' => 100 } }]).send

And I have this result :

{:xmlns=>"urn:ebay:apis:eBLBaseComponents",
 :timestamp=>"2016-04-04T19:49:15.014Z",
 :ack=>"Failure",
 :errors=>
  [{:short_message=>"No <Order.Total.CurrencyID> exists or <Order.Total.CurrencyID> is specified as an empty tag.",
    :long_message=>
     "No <Order.Total.CurrencyID> exists or <Order.Total.CurrencyID> is specified as an empty tag in the request.",
    :error_code=>"10009",
    :severity_code=>"Error",
    :error_parameters=>{:param_id=>"0", :value=>"Order.Total.CurrencyID"},
    :error_classification=>"RequestError"},
   {:short_message=>"No <Order.TransactionArray> exists or <Order.TransactionArray> is specified as an empty tag.",
    :long_message=>
     "No <Order.TransactionArray> exists or <Order.TransactionArray> is specified as an empty tag in the request.",
    :error_code=>"10009",
    :severity_code=>"Error",
    :error_parameters=>{:param_id=>"0", :value=>"Order.TransactionArray"},
    :error_classification=>"RequestError"}],
 :version=>"949",
 :build=>"E949_CORE_API_17895653_R1"}

By reading the code, at this line, is see there is no way to do. I propose to do a Pull Request with a format like :

Ebayr::Request.new(:AddOrder, input: [{ Order: { CreatingUserRole: 'Buyer', 'Total' => { value : 100, attr: { CurrencyID: 'EUR' } } }]).send

What you think ?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.