exercism 0.0.5 → 0.0.6

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2U0NDc4ZmQ5NmI4NjJjNGQzYjY3YjUyMWQxZGM5ZDE4NWUxOGJiMw==
4
+ NGM5OTNiOGM4OGEyOGUxMTRmYzhlODRkYjcxOWQ3YWM3M2U2YmFmMw==
5
5
  data.tar.gz: !binary |-
6
- ZDYwYTkxYzkyNGRlN2I0YjVmYzIwYmNlMGQwZTgzYTY2MDY5OWJlNQ==
6
+ N2RhYzc3MzE2MTg1YjJlM2NlYzY3NzJkYTE1Y2E4Y2JkMDY3NTBjMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2UwY2VmMjNiZDI4N2Y2MjM0YTE1Y2U3YjNlOWMwZThkYTViMzZiMTkyZTZl
10
- NGViZWVkMDk2ZjY5NDg1NjE3MGIzZTU2NjYxYzc4ODQzZTMyNDllNzc0MGUw
11
- OWY3ODgyN2ZkNTU3YmNkY2FhYjk1NmVkZjczMTJlYWEwZGQzZDQ=
9
+ NmVjZTBjZjBlYjVhZGQ3ZTE4YjE1OGQwZDdkZTg4Y2E1MzkwMDE1Zjk0ZGQw
10
+ MWJjOTM0MDIzNWNiNzgzYTJkOWQzZmZkMDViODBkNmJiYjkwN2IxOGFiOTZk
11
+ ZDc0MWIxMTE0Yjk1MDc3ZWNhZjg2NThmMjRmYzk3NGI1MDEyNjM=
12
12
  data.tar.gz: !binary |-
13
- Njg5NjM1Y2FkMGJkYjA1ZGM4ZWYwY2ZhNjhkNDdlOTQyYmZiOTVlZTJjZGU2
14
- ZWUwZGM0MmQ2ZTViZWU2M2Y3OTZlMmJiYjBiODI3YWIwMjdkMjIxMTExN2Qw
15
- NjU2YmI4OTFjOTNjNWY4YzkwOTQxZWQ0NTljZDRmYWY2MTYyNjQ=
13
+ ZDI2NWVjMGI1NjE2MGYxNjU5MTM5NDAzMjNmNjIyOGI5YTdmZTQ1Y2JhMzk2
14
+ YjEyMGJkNzAwNGVkYTcxZDkwMTE1MGJmNzAyMjRlNGEwZDkxZWY0MmNjZmQ0
15
+ MDAzN2NiMTk3MDYwZTc3ZDZmMDc5ZTc5MWRiMjk2OGU5YjVhYzI=
data/lib/cli.rb CHANGED
@@ -4,10 +4,12 @@ class Exercism
4
4
  class CLI < Thor
5
5
 
6
6
  desc "fetch", "Fetch current assignment from exercism.io"
7
+ method_option :host, aliases: '-h', default: 'http://exercism.io', desc: 'the url of the exercism application'
7
8
  def fetch
8
9
  require 'exercism'
9
10
 
10
- assignments = Exercism::Api.fetch_for(Exercism.user, Exercism.project_dir)
11
+ api = Exercism::Api.new(options[:host], Exercism.user, Exercism.project_dir)
12
+ assignments = api.fetch
11
13
  if assignments.empty?
12
14
  puts "No assignments fetched."
13
15
  else
@@ -18,10 +20,12 @@ class Exercism
18
20
  end
19
21
 
20
22
  desc "submit FILE", "Submit code to exercism.io on your current assignment"
23
+ method_option :host, aliases: '-h', default: 'http://exercism.io', desc: 'the url of the exercism application'
21
24
  def submit(file)
22
25
  require 'exercism'
23
26
 
24
- Exercism::Api.submit(File.join(FileUtils.pwd, file), {for: Exercism.user})
27
+ path = File.join(FileUtils.pwd, file)
28
+ Exercism::Api.new(options[:host], Exercism.user).submit(file)
25
29
  end
26
30
 
27
31
  desc "login", "Save exercism.io api credentials"
data/lib/exercism.rb CHANGED
@@ -11,14 +11,6 @@ require 'exercism/api'
11
11
 
12
12
  class Exercism
13
13
 
14
- def self.url
15
- if ENV['EXERCISM_ENV'] == 'test'
16
- 'http://localhost:4567'
17
- else
18
- 'http://exercism.herokuapp.com'
19
- end
20
- end
21
-
22
14
  def self.home
23
15
  Dir.home(Etc.getlogin)
24
16
  end
data/lib/exercism/api.rb CHANGED
@@ -1,22 +1,29 @@
1
1
  class Exercism
2
2
  class Api
3
- def self.conn
4
- conn = Faraday.new(:url => Exercism.url) do |c|
3
+
4
+ attr_reader :url, :user, :project_dir
5
+ def initialize(url, user, project_dir = nil)
6
+ @url = url
7
+ @user = user
8
+ @project_dir = project_dir
9
+ end
10
+
11
+ def conn
12
+ conn = Faraday.new(:url => url) do |c|
5
13
  c.use Faraday::Adapter::NetHttp
6
14
  end
7
15
  end
8
16
 
9
- def self.fetch_for(user, path)
17
+ def fetch
10
18
  response = conn.get do |req|
11
19
  req.url '/api/v1/user/assignments/current'
12
20
  req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
13
21
  req.params['key'] = user.key
14
22
  end
15
- Assignment.save(JSON.parse(response.body), path)
23
+ Assignment.save(JSON.parse(response.body), project_dir)
16
24
  end
17
25
 
18
- def self.submit(filename, options)
19
- user = options[:for]
26
+ def submit(filename)
20
27
  path = File.join(filename)
21
28
  contents = File.read path
22
29
  response = conn.post do |req|
@@ -1,3 +1,3 @@
1
1
  class Exercism
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -36,7 +36,7 @@ class ApiTest < MiniTest::Unit::TestCase
36
36
 
37
37
  Exercism.stub(:home, home) do
38
38
  VCR.use_cassette('alice-gets-bob') do
39
- Exercism::Api.fetch_for(Exercism.user, project_dir)
39
+ Exercism::Api.new('http://localhost:4567', Exercism.user, project_dir).fetch
40
40
 
41
41
  Approvals.verify(File.read(readme_path), name: 'alice_gets_bob_readme')
42
42
  Approvals.verify(File.read(tests_path), name: 'alice_gets_bob_tests')
@@ -54,7 +54,7 @@ class ApiTest < MiniTest::Unit::TestCase
54
54
 
55
55
  Exercism.stub(:home, home) do
56
56
  VCR.use_cassette('alice-submits-bob') do
57
- response = Exercism::Api.submit(submission, {for: Exercism.user})
57
+ response = Exercism::Api.new('http://localhost:4567', Exercism.user).submit(submission)
58
58
  assert_equal 201, response.status
59
59
  end
60
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exercism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-13 00:00:00.000000000 Z
11
+ date: 2013-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday