twenty20 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +19 -1
- data/lib/twenty20.rb +23 -12
- data/lib/twenty20/version.rb +1 -1
- data/spec/client_spec.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4a9f6b147774926e206dc91a7710b4c0a200627
|
4
|
+
data.tar.gz: 1501033229edd7d185bf0ced06a5883ef2684a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1af16a8ece35a9ddb302776a2c938833d1e072180b06b11ea05b9b50816726b4611b0a4b1935c69254e46b7fa0ace6dd050a580b8df53e770dace0a5878549a
|
7
|
+
data.tar.gz: b14966f2f3d0a055601c4391d4f536cabaf5d00687dcee8ff960d51b1b1efcfb63ea147eff3787a66984b2ce50e1bc0c69e95549f7b9949924e08784414ac362
|
data/README.md
CHANGED
@@ -34,12 +34,30 @@ Instantiate a new client
|
|
34
34
|
Get Featured items
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
client.get_featured_items
|
37
|
+
client.get_featured_items
|
38
38
|
```
|
39
|
+
|
39
40
|
```ruby
|
40
41
|
[#<Item:0x007feff9212348 @caption="Red Canoes on Lake Louise", @id=45414069, @source_name="upload", @image_url="https://res.cloudinary.com/twenty20/image/upload/t_standard-fit/photos/cf34293d-1eeb-47a7-94c7-99397dce4c15.jpg", @featured_at="2014-11-29T22:40:04Z", @user_first_name=nil, @user_last_name=nil, @user_avatar_url=nil, @username=nil, @display_name=nil>, #<Item:0x007feff9212190 @caption=nil, @id=49291337, @source_name="instagram", @image_url="http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/1742594_280292302171814_502487005_n.jpg", @featured_at="2014-11-29T22:20:02Z"...]
|
41
42
|
```
|
42
43
|
|
44
|
+
Get featured items and pass a block to do something cool (idk write to a file, send a text message?)
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client.get_featured_items {|item| #do something with each item}
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
Get challenges open for submissions
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client.get_challenges
|
55
|
+
```
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
client.get_challenges {|challenge| #something cool here}
|
59
|
+
```
|
60
|
+
|
43
61
|
## Contributing
|
44
62
|
|
45
63
|
1. Fork it ( https://github.com/AlexWheeler/twenty20_API/fork )
|
data/lib/twenty20.rb
CHANGED
@@ -8,26 +8,38 @@ module Twenty20
|
|
8
8
|
include HTTParty
|
9
9
|
BASE_URI = "https://api-v2.twenty20.com/"
|
10
10
|
|
11
|
-
def get_featured_items
|
11
|
+
def get_featured_items(&block)
|
12
12
|
featured_route = "items/featured"
|
13
13
|
featured_params = "?featured=true"
|
14
14
|
resource = build_route(featured_route, featured_params)
|
15
15
|
response = self.class.get(resource)
|
16
16
|
if(response.code == 200)
|
17
|
-
item_collection =
|
18
|
-
|
17
|
+
item_collection = to_collection(response, "item")
|
18
|
+
if(block_given?)
|
19
|
+
item_collection.each do |item|
|
20
|
+
block.call(item)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
item_collection
|
24
|
+
end
|
19
25
|
else
|
20
26
|
"Error"
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
|
-
def get_challenges
|
30
|
+
def get_challenges(&block)
|
25
31
|
challenges_route = "/challenges/open-for-submissions"
|
26
32
|
resource = build_route(challenges_route)
|
27
33
|
response = self.class.get(resource)
|
28
34
|
if(response.code == 200)
|
29
|
-
challenge_collection =
|
30
|
-
|
35
|
+
challenge_collection = to_collection(response, "challenge")
|
36
|
+
if block_given?
|
37
|
+
challenge_collection.each do |challenge|
|
38
|
+
block.call(challenge)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
challenge_collection
|
42
|
+
end
|
31
43
|
else
|
32
44
|
"Error"
|
33
45
|
end
|
@@ -35,12 +47,11 @@ module Twenty20
|
|
35
47
|
|
36
48
|
private
|
37
49
|
|
38
|
-
def
|
39
|
-
response.parsed_response["
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
response.parsed_response["challenges"].collect {|challenge| Challenge.new(challenge)}
|
50
|
+
def to_collection(response, collection_class)
|
51
|
+
response.parsed_response[collection_class + "s"].collect do |e|
|
52
|
+
o = Object.const_get("Twenty20::" + collection_class.capitalize) #creates new array full of collection_class object (i.e. Items, Challenges)
|
53
|
+
o.new(e)
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
def build_route(uri, params = "")
|
data/lib/twenty20/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -30,8 +30,13 @@ describe Twenty20::Client do
|
|
30
30
|
expect(response).to eq("Error")
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "can accept a block and do something cool like push challenges into a new array" do
|
34
|
+
val = []
|
35
|
+
@client.get_featured_items {|item| val.push(item)}
|
36
|
+
expect(val.empty?).to_not eq(true)
|
37
|
+
|
34
38
|
end
|
39
|
+
|
35
40
|
end
|
36
41
|
|
37
42
|
describe "get_challenges" do
|
@@ -43,5 +48,11 @@ describe Twenty20::Client do
|
|
43
48
|
response = @client.get_challenges
|
44
49
|
expect(response.class).to eq(Array);
|
45
50
|
end
|
51
|
+
|
52
|
+
it "can accept a block and do something cool like push challenges into a new array" do
|
53
|
+
val = []
|
54
|
+
@client.get_challenges {|challenge| val.push(challenge)}
|
55
|
+
expect(val.empty?).to_not eq(true)
|
56
|
+
end
|
46
57
|
end
|
47
58
|
end
|