Browse Source

Include library versions in user-agent header.

Dylan Smith 13 years ago
parent
commit
b11300a023

+ 1 - 1
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)

+ 10 - 0
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 => [])

+ 3 - 0
lib/shopify_api/version.rb

@@ -0,0 +1,3 @@
+module ShopifyAPI
+  VERSION = "2.3.0"
+end

+ 3 - 1
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}

+ 3 - 2
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 @@ class LogSubscriberTest < Test::Unit::TestCase
     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 @@ class LogSubscriberTest < Test::Unit::TestCase
     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