Przeglądaj źródła

added authors and tags to the article api

Kevin Hughes 11 lat temu
rodzic
commit
dafea0a52b

+ 8 - 0
lib/shopify_api/resources/article.rb

@@ -13,5 +13,13 @@ module ShopifyAPI
     def comments
       Comment.find(:all, :params => { :article_id => id })
     end
+
+    def self.authors
+      get(:authors)
+    end
+
+    def self.tags(options={})
+      get(:tags, options)
+    end
   end
 end

+ 28 - 0
test/article_test.rb

@@ -25,4 +25,32 @@ class ArticleTest < Test::Unit::TestCase
     article = ShopifyAPI::Article.find(6242736, :params => {:blog_id => 1008414260})
     assert_equal "First Post", article.title
   end
+
+  def test_get_authors
+    fake "articles/authors", :method => :get, :body => load_fixture('authors')
+    authors = ShopifyAPI::Article.authors
+    assert_equal "Shopify", authors.first
+    assert_equal "development shop", authors.last
+  end
+
+  def test_get_tags
+    fake "articles/tags", :method => :get, :body => load_fixture('tags')
+    tags = ShopifyAPI::Article.tags
+    assert_equal "consequuntur", tags.first
+    assert_equal "repellendus", tags.last
+  end
+
+  def test_get_tags_for_blog_id
+    fake "blogs/1008414260/articles/tags", :method => :get, :body => load_fixture('tags')
+    tags = ShopifyAPI::Article.tags(:blog_id => 1008414260)
+    assert_equal "consequuntur", tags.first
+    assert_equal "repellendus", tags.last
+  end
+
+  def test_get_popular_tags
+    fake "articles/tags.json?limit=1&popular=1", :extension => false, :method => :get, :body => load_fixture('tags')
+    tags = ShopifyAPI::Article.tags(:popular => 1, :limit => 1)
+    puts tags
+  end
+
 end

+ 1 - 0
test/fixtures/authors.json

@@ -0,0 +1 @@
+{"authors": ["Shopify", "development shop", "development shop"]}

+ 1 - 0
test/fixtures/tags.json

@@ -0,0 +1 @@
+{"tags": ["consequuntur", "cupiditate", "repellendus"]}