Permalink
Browse files

Include library versions in user-agent header.

  • Loading branch information...
1 parent ccc46f0 commit b11300a023ba9b1dbfeba69be2ef4384eb5018a2 @dylanahsmith dylanahsmith committed Feb 29, 2012
Showing with 20 additions and 4 deletions.
  1. +1 −1 RELEASING
  2. +10 −0 lib/shopify_api/resources/base.rb
  3. +3 −0 lib/shopify_api/version.rb
  4. +3 −1 shopify_api.gemspec
  5. +3 −2 test/detailed_log_subscriber_test.rb
View
2 RELEASING
@@ -1,7 +1,7 @@
Releasing ShopifyAPI
1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
-2. Update the version of ShopifyAPI in shopify_api.gemspec
+2. Update the version of ShopifyAPI in lib/shopify_api/version.rb
3. Add a CHANGELOG entry for the new release with the date
4. Commit the changes with a commit message like "Packaging for release X.Y.Z"
5. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
View
10 lib/shopify_api/resources/base.rb
@@ -1,8 +1,18 @@
+require 'shopify_api/version'
+
module ShopifyAPI
class Base < ActiveResource::Base
extend Countable
self.include_root_in_json = false
+ def self.inherited(klass)
+ super
+ klass.headers['User-Agent'] = Base.headers['User-Agent']
+ end
+ self.headers['User-Agent'] = ["ShopifyAPI/#{ShopifyAPI::VERSION}",
+ "ActiveResource/#{ActiveResource::VERSION::STRING}",
+ "Ruby/#{RUBY_VERSION}"].join(' ')
+
private
def only_id
encode(:only => :id, :include => [], :methods => [])
View
3 lib/shopify_api/version.rb
@@ -0,0 +1,3 @@
+module ShopifyAPI
+ VERSION = "2.3.0"
+end
View
4 shopify_api.gemspec
@@ -1,8 +1,10 @@
# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "shopify_api/version"
Gem::Specification.new do |s|
s.name = %q{shopify_api}
- s.version = "2.3.0"
+ s.version = ShopifyAPI::VERSION
s.author = "Shopify"
s.summary = %q{The Shopify API gem is a lightweight gem for accessing the Shopify admin REST web services}
View
5 test/detailed_log_subscriber_test.rb
@@ -7,6 +7,7 @@ class LogSubscriberTest < Test::Unit::TestCase
def setup
super
@page = { :page => { :id => 1, :title => 'Shopify API' } }.to_json
+ @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
ShopifyAPI::Base.site = "http://localhost/admin"
@@ -26,7 +27,7 @@ def set_logger(logger)
assert_equal 4, @logger.logged(:info).size
assert_equal "GET http://localhost:80/admin/pages/1.json", @logger.logged(:info)[0]
assert_match /\-\-\> 200/, @logger.logged(:info)[1]
- assert_equal "Headers: {\"Accept\"=>\"application/json\"}", @logger.logged(:info)[2]
+ assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
assert_match /Response:\n\{\"page\"\:\{((\"id\"\:1)|(\"title\"\:\"Shopify API\")),((\"id\"\:1)|(\"title\"\:\"Shopify API\"))\}\}/, @logger.logged(:info)[3]
end
@@ -41,7 +42,7 @@ def set_logger(logger)
assert_equal 4, @logger.logged(:info).size
assert_equal "GET http://localhost:80/admin/pages/2.json", @logger.logged(:info)[0]
assert_match /\-\-\> 404/, @logger.logged(:info)[1]
- assert_equal "Headers: {\"Accept\"=>\"application/json\"}", @logger.logged(:info)[2]
+ assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
assert_equal "Response:", @logger.logged(:info)[3]
end
end

0 comments on commit b11300a

Please sign in to comment.