discourse_api 0.1.2 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96b74f525ab0fe9d044cf6ca8bf4d3dd2eac1c14
4
- data.tar.gz: f814acea9dba0c29147b5bf2569d1f95bb2a6af4
3
+ metadata.gz: 7b27fccecba3357cb727bb0b241e29613ddf4d6c
4
+ data.tar.gz: 9eff8ed55d066031a9ca7b875ecbae247c8f54b7
5
5
  SHA512:
6
- metadata.gz: a60efaf52b2a8c43d5df74046b4df8a50ed5bbe6e39ef7f1565097fe37b2b706322691f78286dab090f7d0916a5961e9e12b2c0517383b45719424fbda589b8e
7
- data.tar.gz: ea0d9fdf0f425e8bcc09ba8e959312b1fb1b879b5abbdb3f86531ef91250b3f6fad407e6077f1ffa4454831e122e012ddab692572ebd43585c902149a318fd71
6
+ metadata.gz: 2dc325485d107e56f286baa033ffbefaf646c32611cfbea7b285a7d628445be7d6e900d7a0626516f6d1fb428d6e8ac6363803349845f51cebba0dbf66c846df
7
+ data.tar.gz: cf520bd3e1baba478c6f4ad7ece1f3419dfccdfdb8fdf6d54cec01a3a1433d06bbf254656b457bfb39e14090e329b05e7a5923518b90af185d105f7065a789e8
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## master
4
+
5
+ * Added `client.category_latest_posts("category-slug")` endpoint
6
+
7
+ ## 0.1.2
8
+
9
+ * Release
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Discourse
1
+ Copyright (c) 2014 Civilized Discourse Construction Kit, Inc.
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -31,18 +31,18 @@ few endpoints available:
31
31
  client = DiscourseApi::Client.new("http://try.discourse.org")
32
32
 
33
33
  # Topic endpoints
34
- client.latest_topics #=> Gets a list of the latest topics
35
- client.hot_topics #=> Gets a list of hot topics
36
- client.new_topics #=> Gets a list of new topics
37
- client.topics_by("sam") #=> Gets a list of topics created by user "sam"
38
- client.topic(57) #=> Gets the topic with id 57
34
+ client.latest_topics #=> Gets a list of the latest topics
35
+ client.hot_topics #=> Gets a list of hot topics
36
+ client.new_topics #=> Gets a list of new topics
37
+ client.topics_by("sam") #=> Gets a list of topics created by user "sam"
38
+ client.topic(57) #=> Gets the topic with id 57
39
39
 
40
40
  # Search endpoint
41
- client.search("sandbox") #=> Gets a list of topics that match "sandbox"
41
+ client.search("sandbox") #=> Gets a list of topics that match "sandbox"
42
42
 
43
43
  # Categories endpoint
44
- client.categories #=> Gets a list of categories
45
-
44
+ client.categories #=> Gets a list of categories
45
+ client.category_latest_posts("category-slug") #=> Gets a list of latest posts in a category
46
46
  ```
47
47
 
48
48
 
@@ -53,3 +53,10 @@ client.categories #=> Gets a list of categories
53
53
  3. Commit your changes (`git commit -am 'Add some feature'`)
54
54
  4. Push to the branch (`git push origin my-new-feature`)
55
55
  5. Create new Pull Request
56
+
57
+ ## Testing
58
+
59
+ 1. Install discourse locally
60
+ 2. Inside of your discourse directory, run: `bundle exec rake db:api_test_seed`
61
+ 3. Start discourse: `bundle exec rails s`
62
+ 4. Inside of your discourse_api directory, run: `bundle exec rspec spec/`
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task test: :spec
7
- task default: :spec
7
+ task default: :spec
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "faraday", "~> 0.8.8"
21
+ spec.add_dependency "faraday", "0.9.0"
22
22
  spec.add_dependency "faraday_middleware", "~> 0.9"
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "webmock"
27
- spec.add_development_dependency "guard-rspec"
28
- spec.add_development_dependency "guard"
29
- spec.add_development_dependency "rb-inotify"
30
- spec.add_development_dependency "simplecov"
24
+ spec.add_development_dependency "rake", "10.3.2"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 1.18"
27
+ spec.add_development_dependency "guard-rspec", "~> 4.3"
28
+ spec.add_development_dependency "guard", "~> 2.6"
29
+ spec.add_development_dependency "rb-inotify", "~> 0.9"
30
+ spec.add_development_dependency "simplecov", "~> 0.9"
31
31
  end
@@ -1,13 +1,11 @@
1
- # require 'discourse_api'
2
-
3
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
  require File.expand_path('../../lib/discourse_api', __FILE__)
5
3
 
6
- client = DiscourseApi::Client.new("localhost", 3000)
4
+ client = DiscourseApi::Client.new("http://localhost:3000")
7
5
  client.api_key = "YOUR_API_KEY"
8
6
  client.api_username = "YOUR_USERNAME"
9
7
 
10
- client.post_create(
8
+ client.create_topic(
11
9
  category: "Boing Boing",
12
10
  skip_validations: true,
13
11
  auto_track: false,
@@ -0,0 +1,19 @@
1
+ require 'csv'
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require File.expand_path('../../lib/discourse_api', __FILE__)
5
+
6
+ client = DiscourseApi::Client.new("http://localhost:3000")
7
+ client.api_key = "YOUR_API_KEY"
8
+ client.api_username = "YOUR_USERNAME"
9
+
10
+ # fetch email-less invite tokens
11
+ invite_tokens = client.disposable_tokens(username: "eviltrout", quantity: 5, group_names: "security,support")
12
+ invite_tokens_array = invite_tokens.body
13
+
14
+ # write to CSV file
15
+ CSV.open(File.expand_path("../invite_tokens.csv", __FILE__), "w") do |csv|
16
+ invite_tokens_array.each do |value|
17
+ csv << [value]
18
+ end
19
+ end
@@ -1,7 +1,9 @@
1
- # require 'discourse_api'
2
-
3
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
  require File.expand_path('../../lib/discourse_api', __FILE__)
5
3
 
6
- client = DiscourseApi::Client.new("http://localhost:3000", '6157bad92b3b5f8004aedc82220281c5966e5d560bb2bb6f962123474db4ac98', 'user_name')
7
- puts client.latest_topics
4
+ client = DiscourseApi::Client.new("http://localhost:3000")
5
+ client.api_key = "YOUR_API_KEY"
6
+ client.api_username = "YOUR_USERNAME"
7
+
8
+ # get latest topics
9
+ puts client.latest_topics
@@ -1,14 +1,12 @@
1
- # require 'discourse_api'
2
-
3
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
  require File.expand_path('../../lib/discourse_api', __FILE__)
5
3
 
6
- client = DiscourseApi::Client.new("localhost",3000)
7
- client.api_key = "6157bad92b3b5f8004aedc82220281c5966e5d560bb2bb6f962123474db4ac98"
8
- client.api_username = "forumadmin"
4
+ client = DiscourseApi::Client.new("http://localhost:3000")
5
+ client.api_key = "YOUR_API_KEY"
6
+ client.api_username = "YOUR_USERNAME"
9
7
 
10
- client.topic_invite_user(topic_id: 1, email: "bob@bob.com")
8
+ # invite to a topic
9
+ client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
11
10
 
12
11
  # if the user is an admin you may invite to a group as well
13
- client.topic_invite_user(topic_id: 1, email: "bob@bob.com", group_ids: "1,2,3")
14
- client.topic_invite_user(topic_id: 1, email: "bob@bob.com", group_names: "bugs,cars,testers")
12
+ client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1, group_ids: "1,2,3")
@@ -1,13 +1,11 @@
1
- # require 'discourse_api'
2
-
3
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
  require File.expand_path('../../lib/discourse_api', __FILE__)
5
3
 
6
- client = DiscourseApi::Client.new("localhost", 3000)
4
+ client = DiscourseApi::Client.new("http://localhost:3000")
7
5
  client.api_key = "YOUR_API_KEY"
8
6
  client.api_username = "YOUR_USERNAME"
9
7
 
8
+ # get latest topics
10
9
  puts client.latest_topics({})
11
- puts client.hot_topics({})
10
+ # get all categories
12
11
  puts client.categories({})
13
-
@@ -1,5 +1,3 @@
1
- # require 'discourse_api'
2
-
3
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
  require File.expand_path('../../lib/discourse_api', __FILE__)
5
3
 
@@ -7,8 +5,11 @@ client = DiscourseApi::Client.new("localhost", 3000)
7
5
  client.api_key = "YOUR_API_KEY"
8
6
  client.api_username = "YOUR_USERNAME"
9
7
 
10
- puts client.username_update(username: "Batman", new_username: "Alfred")
11
- puts client.user_update(username: "Batman", name: "Bruce Wayne")
12
- puts client.email_update(username: "Batman", email: "batman@example.com")
13
- puts client.toggle_avatar(username: "Batman", use_uploaded_avatar: true)
14
- puts client.upload_avatar(username: "DiscourseHero", file: "http://cdn.discourse.org/assets/logo.png")
8
+ # update username from "robin" to "batman"
9
+ puts client.update_username("robin", "batman")
10
+ # update name of user whose username is "batman"
11
+ puts client.update_user("batman", name: "Bruce Wayne")
12
+ # update email of user whose username is "batman"
13
+ puts client.update_email("batman", "batman@gotham.com")
14
+ # update avatar of user whose username is "batman"
15
+ puts client.update_avatar("batman", "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
@@ -1,3 +1,3 @@
1
1
  require "discourse_api/client"
2
2
  require "discourse_api/error"
3
- require "discourse_api/version"
3
+ require "discourse_api/version"
@@ -5,6 +5,11 @@ module DiscourseApi
5
5
  response = get('/categories.json', args)
6
6
  response[:body]['category_list']['categories']
7
7
  end
8
+
9
+ def category_latest_topics(category_slug)
10
+ response = get("/category/#{category_slug}.json")
11
+ response[:body]['topic_list']['topics']
12
+ end
8
13
  end
9
14
  end
10
- end
15
+ end
@@ -0,0 +1,13 @@
1
+ module DiscourseApi
2
+ module API
3
+ module Invite
4
+ def invite_user_to_topic(params={})
5
+ post("/t/#{params[:topic_id]}/invite", params)
6
+ end
7
+
8
+ def disposable_tokens(params={})
9
+ post("/invites/disposable", params)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,4 +13,4 @@ module DiscourseApi
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -1,14 +1,8 @@
1
1
  module DiscourseApi
2
2
  module API
3
3
  module Topics
4
- def hot_topics(*args)
5
- response = get('/hot.json', args)
6
- response[:body]['topic_list']['topics']
7
- end
8
-
9
- def invite_user_to_topic(user_email, topic_id)
10
- params = { email: user_email, topic_id: topic_id }
11
- post "/t/#{topic_id}/invite.json", params
4
+ def create_topic(params={})
5
+ post("/posts", params)
12
6
  end
13
7
 
14
8
  def latest_topics(*args)
@@ -32,4 +26,4 @@ module DiscourseApi
32
26
  end
33
27
  end
34
28
  end
35
- end
29
+ end
@@ -1,10 +1,6 @@
1
1
  module DiscourseApi
2
2
  module API
3
3
  module Users
4
- def toggle_avatar(username, use_uploaded_avatar)
5
- put("/users/#{username}/preferences/avatar/toggle", { use_uploaded_avatar: use_uploaded_avatar })
6
- end
7
-
8
4
  def activate(id)
9
5
  put "/admin/users/#{id}/activate", api_key: api_key, api_username: api_username
10
6
  end
@@ -22,8 +18,8 @@ module DiscourseApi
22
18
  put("/users/#{username}/preferences/email", { email: email, api_key: api_key })
23
19
  end
24
20
 
25
- def update_user(username, *args)
26
- put("/users/#{username}", args)
21
+ def update_user(username, params={})
22
+ put("/users/#{username}", params)
27
23
  end
28
24
 
29
25
  def update_username(username, new_username)
@@ -42,4 +38,4 @@ module DiscourseApi
42
38
  end
43
39
  end
44
40
  end
45
- end
41
+ end
@@ -6,6 +6,7 @@ require 'discourse_api/api/categories'
6
6
  require 'discourse_api/api/search'
7
7
  require 'discourse_api/api/topics'
8
8
  require 'discourse_api/api/users'
9
+ require 'discourse_api/api/invite'
9
10
 
10
11
  module DiscourseApi
11
12
  class Client
@@ -16,10 +17,11 @@ module DiscourseApi
16
17
  include DiscourseApi::API::Search
17
18
  include DiscourseApi::API::Topics
18
19
  include DiscourseApi::API::Users
20
+ include DiscourseApi::API::Invite
19
21
 
20
22
  def initialize(host, api_key=nil, api_username=nil)
21
- @host = host
22
- @api_key = api_key
23
+ @host = host
24
+ @api_key = api_key
23
25
  @api_username = api_username
24
26
  end
25
27
 
@@ -57,10 +59,12 @@ module DiscourseApi
57
59
 
58
60
  def connection
59
61
  @connection ||= Faraday.new connection_options do |conn|
62
+ # Follow redirects
63
+ conn.use FaradayMiddleware::FollowRedirects, limit: 5
60
64
  # Convert request params to "www-form-encoded"
61
65
  conn.request :url_encoded
62
66
  # Parse responses as JSON
63
- conn.response :json
67
+ conn.use FaradayMiddleware::ParseJson, content_type: 'application/json'
64
68
  # Use Faraday's default HTTP adapter
65
69
  conn.adapter Faraday.default_adapter
66
70
  #pass api_key and api_username on every request
@@ -11,4 +11,4 @@ module DiscourseApi
11
11
  exception.respond_to?(:message) ? super(exception.message) : super(exception.to_s)
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module DiscourseApi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,22 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Categories do
4
- subject { DiscourseApi::Client.new("http://localhost") }
4
+ subject { DiscourseApi::Client.new("http://localhost:3000") }
5
5
 
6
6
  describe "#categories" do
7
7
  before do
8
- stub_get("http://localhost/categories.json").to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
8
+ stub_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
+ subject.api_key = 'test_d7fd0429940'
13
+ subject.api_username = 'test_user'
12
14
  subject.categories
13
- expect(a_get("http://localhost/categories.json")).to have_been_made
15
+ expect(a_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
14
16
  end
15
17
 
16
18
  it "returns the requested categories" do
19
+ subject.api_key = 'test_d7fd0429940'
20
+ subject.api_username = 'test_user'
17
21
  categories = subject.categories
18
22
  expect(categories).to be_an Array
19
23
  expect(categories.first).to be_a Hash
20
24
  end
21
25
  end
22
- end
26
+
27
+ describe '#category_latest_topics' do
28
+ before do
29
+ stub_get("http://localhost:3000/category/category-slug.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
30
+ end
31
+
32
+ it "returns the latest topics in a category" do
33
+ subject.api_key = 'test_d7fd0429940'
34
+ subject.api_username = 'test_user'
35
+ latest_topics = subject.category_latest_topics('category-slug')
36
+ expect(latest_topics).to be_an Array
37
+ end
38
+ end
39
+ end
@@ -1,22 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Search do
4
- subject { DiscourseApi::Client.new("http://localhost") }
4
+ subject { DiscourseApi::Client.new("http://localhost:3000") }
5
5
 
6
6
  describe "#search" do
7
7
  before do
8
- stub_get("http://localhost/search.json").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
8
+ stub_get("http://localhost:3000/search.json?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
+ subject.api_key = 'test_d7fd0429940'
13
+ subject.api_username = 'test_user'
12
14
  subject.search("test")
13
- expect(a_get("http://localhost/search.json").with(query: { term: "test"} )).to have_been_made
15
+ expect(a_get("http://localhost:3000/search.json?api_key=test_d7fd0429940&api_username=test_user").with(query: { term: "test"} )).to have_been_made
14
16
  end
15
17
 
16
18
  it "returns the requested search" do
19
+ subject.api_key = 'test_d7fd0429940'
20
+ subject.api_username = 'test_user'
17
21
  results = subject.search("test")
18
22
  expect(results).to be_an Array
19
23
  expect(results.first).to be_a Hash
20
24
  end
21
25
  end
22
- end
26
+ end
@@ -1,24 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Topics do
4
- subject { DiscourseApi::Client.new("http://localhost") }
5
-
6
- describe "#hot_topics" do
7
- before do
8
- stub_get("http://localhost/hot.json").to_return(body: fixture("hot.json"), headers: { content_type: "application/json" })
9
- end
10
-
11
- it "requests the correct resource" do
12
- subject.hot_topics
13
- expect(a_get("http://localhost/hot.json")).to have_been_made
14
- end
15
-
16
- it "returns the requested topics" do
17
- topics = subject.hot_topics
18
- expect(topics).to be_an Array
19
- expect(topics.first).to be_a Hash
20
- end
21
- end
4
+ subject { DiscourseApi::Client.new("http://localhost:3000") }
22
5
 
23
6
  describe "#invite_user_to_topic" do
24
7
  it "needs to have a test written for it"
@@ -26,15 +9,19 @@ describe DiscourseApi::API::Topics do
26
9
 
27
10
  describe "#latest_topics" do
28
11
  before do
29
- stub_get("http://localhost/latest.json").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
12
+ stub_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
30
13
  end
31
14
 
32
15
  it "requests the correct resource" do
16
+ subject.api_key = 'test_d7fd0429940'
17
+ subject.api_username = 'test_user'
33
18
  subject.latest_topics
34
- expect(a_get("http://localhost/latest.json")).to have_been_made
19
+ expect(a_get("http://localhost:3000/latest.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
35
20
  end
36
21
 
37
22
  it "returns the requested topics" do
23
+ subject.api_key = 'test_d7fd0429940'
24
+ subject.api_username = 'test_user'
38
25
  topics = subject.latest_topics
39
26
  expect(topics).to be_an Array
40
27
  expect(topics.first).to be_a Hash
@@ -43,15 +30,19 @@ describe DiscourseApi::API::Topics do
43
30
 
44
31
  describe "#new_topics" do
45
32
  before do
46
- stub_get("http://localhost/new.json").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
33
+ stub_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
47
34
  end
48
35
 
49
36
  it "requests the correct resource" do
37
+ subject.api_key = 'test_d7fd0429940'
38
+ subject.api_username = 'test_user'
50
39
  subject.new_topics
51
- expect(a_get("http://localhost/new.json")).to have_been_made
40
+ expect(a_get("http://localhost:3000/new.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
52
41
  end
53
42
 
54
43
  it "returns the requested topics" do
44
+ subject.api_key = 'test_d7fd0429940'
45
+ subject.api_username = 'test_user'
55
46
  topics = subject.new_topics
56
47
  expect(topics).to be_an Array
57
48
  expect(topics.first).to be_a Hash
@@ -60,15 +51,19 @@ describe DiscourseApi::API::Topics do
60
51
 
61
52
  describe "#topic" do
62
53
  before do
63
- stub_get("http://localhost/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
54
+ stub_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
64
55
  end
65
56
 
66
57
  it "requests the correct resource" do
58
+ subject.api_key = 'test_d7fd0429940'
59
+ subject.api_username = 'test_user'
67
60
  subject.topic(57)
68
- expect(a_get("http://localhost/t/57.json")).to have_been_made
61
+ expect(a_get("http://localhost:3000/t/57.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
69
62
  end
70
63
 
71
64
  it "returns the requested topic" do
65
+ subject.api_key = 'test_d7fd0429940'
66
+ subject.api_username = 'test_user'
72
67
  topic = subject.topic(57)
73
68
  expect(topic).to be_a Hash
74
69
  expect(topic["id"]).to eq(57)
@@ -77,18 +72,22 @@ describe DiscourseApi::API::Topics do
77
72
 
78
73
  describe "#topics_by" do
79
74
  before do
80
- stub_get("http://localhost/topics/created-by/test_user.json").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
75
+ stub_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
81
76
  end
82
77
 
83
78
  it "requests the correct resource" do
84
- subject.topics_by('test_user')
85
- expect(a_get("http://localhost/topics/created-by/test_user.json")).to have_been_made
79
+ subject.api_key = 'test_d7fd0429940'
80
+ subject.api_username = 'test_user'
81
+ subject.topics_by('test')
82
+ expect(a_get("http://localhost:3000/topics/created-by/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
86
83
  end
87
84
 
88
85
  it "returns the requested topics" do
89
- topics = subject.topics_by('test_user')
86
+ subject.api_key = 'test_d7fd0429940'
87
+ subject.api_username = 'test_user'
88
+ topics = subject.topics_by('test')
90
89
  expect(topics).to be_an Array
91
90
  expect(topics.first).to be_a Hash
92
91
  end
93
92
  end
94
- end
93
+ end
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Users do
4
- subject { DiscourseApi::Client.new("http://localhost") }
5
-
6
- describe "#toggle_avatar" do
7
- it "needs to have a test written for it"
8
- end
4
+ subject { DiscourseApi::Client.new("http://localhost:3000") }
9
5
 
10
6
  describe "#user" do
11
7
  before do
12
- stub_get("http://localhost/users/test_user.json").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
8
+ stub_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
13
9
  end
14
10
 
15
11
  it "requests the correct resource" do
16
- subject.user("test_user")
17
- expect(a_get("http://localhost/users/test_user.json")).to have_been_made
12
+ subject.api_key = 'test_d7fd0429940'
13
+ subject.api_username = 'test_user'
14
+ subject.user("test")
15
+ expect(a_get("http://localhost:3000/users/test.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
18
16
  end
19
17
 
20
18
  it "returns the requested user" do
21
- user = subject.user("test_user")
19
+ subject.api_key = 'test_d7fd0429940'
20
+ subject.api_username = 'test_user'
21
+ user = subject.user("test")
22
22
  expect(user).to be_a Hash
23
23
  end
24
24
  end
@@ -41,18 +41,22 @@ describe DiscourseApi::API::Users do
41
41
 
42
42
  describe "#create_user" do
43
43
  before do
44
- stub_post("http://localhost/users").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
45
- stub_get("http://localhost/users/hp.json").to_return(body: {"value"=>"foo", "challenge"=>"bar"}.to_json, headers: { content_type: "application/json" })
44
+ stub_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_create_success.json"), headers: { content_type: "application/json" })
45
+ stub_get("http://localhost:3000/users/hp.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: {"value"=>"foo", "challenge"=>"bar"}.to_json, headers: { content_type: "application/json" })
46
46
  end
47
47
 
48
48
  it "makes the post request" do
49
- subject.create_user :name => "Test User", :email => "test@example.com", :password => "P@ssword", :username => "test-user"
50
- expect(a_post("http://localhost/users")).to have_been_made
49
+ subject.api_key = 'test_d7fd0429940'
50
+ subject.api_username = 'test_user'
51
+ subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
52
+ expect(a_post("http://localhost:3000/users?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
51
53
  end
52
54
 
53
55
  it "returns success" do
54
- response = subject.create_user :name => "Test User", :email => "test@example.com", :password => "P@ssword", :username => "test-user"
55
- expect(response[:body]['success']).to be_true
56
+ subject.api_key = 'test_d7fd0429940'
57
+ subject.api_username = 'test_user'
58
+ response = subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
59
+ expect(response[:body]['success']).to be_truthy
56
60
  end
57
61
  end
58
- end
62
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::Client do
4
- subject { DiscourseApi::Client.new('http://localhost') }
4
+ subject { DiscourseApi::Client.new('http://localhost:3000') }
5
5
 
6
6
  describe ".new" do
7
7
  it "requires a host argument" do
@@ -17,20 +17,20 @@ describe DiscourseApi::Client do
17
17
  end
18
18
 
19
19
  it "accepts an api key argument" do
20
- client = DiscourseApi::Client.new('http://localhost', 'test')
20
+ client = DiscourseApi::Client.new('http://localhost:3000', 'test')
21
21
  expect(client.api_key).to eq('test')
22
22
  end
23
23
 
24
24
  it "accepts an api username argument" do
25
- client = DiscourseApi::Client.new('http://localhost', 'test', 'test_user')
25
+ client = DiscourseApi::Client.new('http://localhost:3000', 'test', 'test_user')
26
26
  expect(client.api_username).to eq('test_user')
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#api_key" do
31
31
  it "is publically accessible" do
32
- subject.api_key = "test_key"
33
- expect(subject.api_key).to eq("test_key")
32
+ subject.api_key = "test_d7fd0429940"
33
+ expect(subject.api_key).to eq("test_d7fd0429940")
34
34
  end
35
35
  end
36
36
 
@@ -43,7 +43,7 @@ describe DiscourseApi::Client do
43
43
 
44
44
  describe "#host" do
45
45
  it "is publically readable" do
46
- expect(subject.host).to eq("http://localhost")
46
+ expect(subject.host).to eq("http://localhost:3000")
47
47
  end
48
48
 
49
49
  it "is not publically writeable" do
@@ -55,7 +55,7 @@ describe DiscourseApi::Client do
55
55
  it "looks like a Faraday connection" do
56
56
  expect(subject.send(:connection)).to respond_to :run_request
57
57
  end
58
- it "memoizes the connection" do
58
+ it "memorizes the connection" do
59
59
  c1, c2 = subject.send(:connection), subject.send(:connection)
60
60
  expect(c1.object_id).to eq(c2.object_id)
61
61
  end
@@ -63,32 +63,38 @@ describe DiscourseApi::Client do
63
63
 
64
64
  describe "#delete" do
65
65
  before do
66
- stub_delete("http://localhost/test/delete").with(query: { deleted: "object" })
66
+ stub_delete("http://localhost:3000/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })
67
67
  end
68
68
  it "allows custom delete requests" do
69
+ subject.api_key = 'test_d7fd0429940'
70
+ subject.api_username = 'test_user'
69
71
  subject.delete("/test/delete", { deleted: "object" })
70
- expect(a_delete("http://localhost/test/delete").with(query: { deleted: "object" })).to have_been_made
72
+ expect(a_delete("http://localhost:3000/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })).to have_been_made
71
73
  end
72
74
  end
73
75
 
74
76
  describe "#post" do
75
77
  before do
76
- stub_post("http://localhost/test/post").with(body: { created: "object"})
78
+ stub_post("http://localhost:3000/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})
77
79
  end
78
80
 
79
81
  it "allows custom post requests" do
82
+ subject.api_key = 'test_d7fd0429940'
83
+ subject.api_username = 'test_user'
80
84
  subject.post("/test/post", { created: "object" })
81
- expect(a_post("http://localhost/test/post").with(body: { created: "object"})).to have_been_made
85
+ expect(a_post("http://localhost:3000/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})).to have_been_made
82
86
  end
83
87
  end
84
88
 
85
89
  describe "#put" do
86
90
  before do
87
- stub_put("http://localhost/test/put").with(body: { updated: "object" })
91
+ stub_put("http://localhost:3000/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })
88
92
  end
89
- it "allows custom delete requests" do
93
+ it "allows custom put requests" do
94
+ subject.api_key = 'test_d7fd0429940'
95
+ subject.api_username = 'test_user'
90
96
  subject.put("/test/put", { updated: "object" })
91
- expect(a_put("http://localhost/test/put").with(body: { updated: "object" })).to have_been_made
97
+ expect(a_put("http://localhost:3000/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })).to have_been_made
92
98
  end
93
99
  end
94
100
 
@@ -0,0 +1 @@
1
+ {"users":[{"id":3,"username":"fuzzy","avatar_template":"//www.gravatar.com/avatar/c0c59575e86a794d733db4ee29b2baf4.png?s={size}&r=pg&d=identicon"}],"topic_list":{"can_create_topic":true,"draft":null,"draft_key":"new_topic","draft_sequence":2,"topics":[{"id":5,"title":"About the category","fancy_title":"About the category","slug":"about-the-category","posts_count":2,"reply_count":0,"highest_post_number":2,"image_url":null,"created_at":"2014-04-16T14:10:50.950-04:00","last_posted_at":"2014-04-16T14:31:10.406-04:00","bumped":true,"bumped_at":"2014-04-17T13:35:01.102-04:00","unseen":false,"last_read_post_number":2,"unread":0,"new_posts":0,"pinned":true,"unpinned":null,"excerpt":null,"visible":true,"closed":false,"archived":false,"views":0,"like_count":0,"starred":false,"has_summary":false,"archetype":"regular","last_poster_username":"fuzzy","category_id":2,"posters":[{"extras":"latest","description":"Original Poster, Most Recent Poster","user_id":3}]},{"id":4,"title":"This is a markdown post","fancy_title":"This is a markdown post","slug":"this-is-a-markdown-post","posts_count":2,"reply_count":0,"highest_post_number":2,"image_url":null,"created_at":"2014-04-16T13:52:58.777-04:00","last_posted_at":"2014-04-16T14:31:37.371-04:00","bumped":true,"bumped_at":"2014-04-16T14:31:37.371-04:00","unseen":false,"last_read_post_number":2,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"views":0,"like_count":0,"starred":false,"has_summary":false,"archetype":"regular","last_poster_username":"fuzzy","category_id":2,"posters":[{"extras":"latest","description":"Original Poster, Most Recent Poster","user_id":3}]}]}}
@@ -1 +1 @@
1
- {"user":{"id":1,"username":"test-user","avatar_template":"http://try.discourse.org/uploads/try_discourse/avatars/a/b/c/{size}.gif","name":"Test User","email":"test@example.com","last_posted_at":null,"last_seen_at":"2013-11-06T21:57:26.260-05:00","bio_raw":null,"bio_cooked":null,"created_at":"2013-11-06T10:56:23.687-05:00","website":"http://example.com","can_edit":true,"can_edit_username":true,"can_edit_email":true,"stats":[{"action_type":13,"count":1,"id":null}],"can_send_private_message_to_user":false,"bio_excerpt":"I&#39;m a test user.","trust_level":1,"moderator":false,"admin":false,"title":null,"email_digests":false,"email_private_messages":true,"email_direct":true,"email_always":false,"digest_after_days":null,"auto_track_topics_after_msecs":240000,"new_topic_duration_minutes":2880,"external_links_in_new_tab":false,"dynamic_favicon":false,"enable_quoting":true,"use_uploaded_avatar":true,"has_uploaded_avatar":true,"gravatar_template":"//www.gravatar.com/avatar/test.png?s={size}&r=pg&d=identicon","uploaded_avatar_template":"http://try.discourse.org/uploads/try_discourse/avatars/a/b/c/{size}.gif","invited_by":null}}
1
+ {"user_badges":[],"user":{"id":1,"username":"test_user","uploaded_avatar_id":null,"avatar_template":"/letter_avatar/test/{size}/2.png","name":"Test User","email":"test_user@example.com","last_posted_at":null,"last_seen_at":"2014-09-04T08:22:19.370-04:00","bio_cooked":null,"created_at":"2014-09-04T08:04:25.104-04:00","can_edit":true,"can_edit_username":true,"can_edit_email":true,"can_edit_name":true,"stats":[{"action_type":13,"count":1,"id":null}],"can_send_private_message_to_user":true,"bio_excerpt":"<div class='missing-profile'>test hasn't entered anything in the About Me field of their profile yet</div>","trust_level":0,"moderator":false,"admin":false,"title":null,"badge_count":0,"has_title_badges":false,"custom_fields":{},"number_of_deleted_posts":0,"number_of_flagged_posts":0,"number_of_flags_given":0,"number_of_suspensions":0,"locale":null,"email_digests":true,"email_private_messages":true,"email_direct":true,"email_always":false,"digest_after_days":7,"mailing_list_mode":false,"auto_track_topics_after_msecs":240000,"new_topic_duration_minutes":2880,"external_links_in_new_tab":false,"dynamic_favicon":false,"enable_quoting":true,"muted_category_ids":[],"tracked_category_ids":[],"watched_category_ids":[],"private_messages_stats":{"all":1,"mine":0,"unread":0},"disable_jump_reply":false,"gravatar_avatar_upload_id":null,"custom_avatar_upload_id":null,"invited_by":null,"custom_groups":[],"featured_user_badge_ids":[]}}
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "success": true,
3
3
  "active": false,
4
- "message": "You're almost done! We sent an activation email to <b>test@example.com</b>. Please follow the instructions in the email to activate your account."
5
- }
4
+ "message": "You're almost done! We sent an activation email to <b>test2@example.com</b>. Please follow the instructions in the email to activate your account."
5
+ }
@@ -17,7 +17,7 @@ RSpec.configure do |config|
17
17
  end
18
18
  end
19
19
 
20
- WebMock.disable_net_connect!
20
+ WebMock.disable_net_connect!(:allow_localhost => true)
21
21
 
22
22
  def a_delete(path)
23
23
  a_request(:delete, path)
@@ -57,4 +57,4 @@ end
57
57
 
58
58
  def fixture(file)
59
59
  File.new(fixture_path + '/' + file)
60
- end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-11 00:00:00.000000000 Z
13
+ date: 2014-09-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.8.8
21
+ version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.8.8
28
+ version: 0.9.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: faraday_middleware
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -58,100 +58,100 @@ dependencies:
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: '0'
63
+ version: 10.3.2
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 10.3.2
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '3.0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '0'
84
+ version: '3.0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: webmock
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '0'
91
+ version: '1.18'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: '0'
98
+ version: '1.18'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: guard-rspec
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: '0'
105
+ version: '4.3'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '0'
112
+ version: '4.3'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ">="
117
+ - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: '0'
119
+ version: '2.6'
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ">="
124
+ - - "~>"
125
125
  - !ruby/object:Gem::Version
126
- version: '0'
126
+ version: '2.6'
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: rb-inotify
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">="
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
- version: '0'
133
+ version: '0.9'
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - "~>"
139
139
  - !ruby/object:Gem::Version
140
- version: '0'
140
+ version: '0.9'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: simplecov
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ">="
145
+ - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: '0'
147
+ version: '0.9'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - ">="
152
+ - - "~>"
153
153
  - !ruby/object:Gem::Version
154
- version: '0'
154
+ version: '0.9'
155
155
  description: Discourse API
156
156
  email:
157
157
  - sam.saffron@gmail.com
@@ -163,19 +163,22 @@ extra_rdoc_files: []
163
163
  files:
164
164
  - ".gitignore"
165
165
  - ".travis.yml"
166
+ - CHANGELOG.md
166
167
  - Gemfile
167
168
  - Guardfile
168
169
  - LICENSE.txt
169
170
  - README.md
170
171
  - Rakefile
171
172
  - discourse_api.gemspec
173
+ - examples/create_topic.rb
174
+ - examples/disposable_invite_tokens.rb
172
175
  - examples/example.rb
173
176
  - examples/invite_users.rb
174
- - examples/post_topic.rb
175
177
  - examples/topic_lists.rb
176
178
  - examples/update_user.rb
177
179
  - lib/discourse_api.rb
178
180
  - lib/discourse_api/api/categories.rb
181
+ - lib/discourse_api/api/invite.rb
179
182
  - lib/discourse_api/api/search.rb
180
183
  - lib/discourse_api/api/topics.rb
181
184
  - lib/discourse_api/api/users.rb
@@ -189,6 +192,7 @@ files:
189
192
  - spec/discourse_api/api/users_spec.rb
190
193
  - spec/discourse_api/client_spec.rb
191
194
  - spec/fixtures/categories.json
195
+ - spec/fixtures/category_latest_topics.json
192
196
  - spec/fixtures/hot.json
193
197
  - spec/fixtures/latest.json
194
198
  - spec/fixtures/new.json
@@ -229,6 +233,7 @@ test_files:
229
233
  - spec/discourse_api/api/users_spec.rb
230
234
  - spec/discourse_api/client_spec.rb
231
235
  - spec/fixtures/categories.json
236
+ - spec/fixtures/category_latest_topics.json
232
237
  - spec/fixtures/hot.json
233
238
  - spec/fixtures/latest.json
234
239
  - spec/fixtures/new.json