mavenlink-ruby 0.0.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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.env +1 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +30 -0
  5. data/Gemfile +18 -0
  6. data/Gemfile.lock +74 -0
  7. data/LICENSE +21 -0
  8. data/README.md +7 -0
  9. data/Rakefile +12 -0
  10. data/fixtures/vcr_cassettes/Mavenlink_CustomFieldValue/_list/a_subject_type_is_provided/should_be_listable.yml +55 -0
  11. data/fixtures/vcr_cassettes/Mavenlink_CustomFieldValue/_retrieve/should_be_retrievable.yml +55 -0
  12. data/fixtures/vcr_cassettes/Mavenlink_Invoice/_list/should_be_listable.yml +89 -0
  13. data/fixtures/vcr_cassettes/Mavenlink_Invoice/_retrieve/should_be_retrievable.yml +55 -0
  14. data/fixtures/vcr_cassettes/Mavenlink_Workspace/_list/should_be_listable.yml +108 -0
  15. data/fixtures/vcr_cassettes/Mavenlink_Workspace/_list_invoices/should_list_the_Invoices_for_the_provided_Workspace_id.yml +57 -0
  16. data/fixtures/vcr_cassettes/Mavenlink_Workspace/_retrieve/should_be_retrievable.yml +57 -0
  17. data/fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_list/should_be_listable.yml +74 -0
  18. data/fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_list_workspaces/should_list_the_Workspaces_for_the_provided_WorkspaceGroup_id.yml +57 -0
  19. data/fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_retrieve/should_be_retrievable.yml +56 -0
  20. data/lib/mavenlink.rb +31 -0
  21. data/lib/mavenlink/api_operations/request.rb +41 -0
  22. data/lib/mavenlink/api_resource.rb +70 -0
  23. data/lib/mavenlink/list.rb +59 -0
  24. data/lib/mavenlink/resources.rb +6 -0
  25. data/lib/mavenlink/resources/custom_field_value.rb +24 -0
  26. data/lib/mavenlink/resources/invoice.rb +16 -0
  27. data/lib/mavenlink/resources/workspace.rb +12 -0
  28. data/lib/mavenlink/resources/workspace_group.rb +25 -0
  29. data/lib/mavenlink/util.rb +23 -0
  30. data/mavenlink-ruby.gemspec +20 -0
  31. data/spec/.rubocop.yml +20 -0
  32. data/spec/lib/mavenlink/list_spec.rb +185 -0
  33. data/spec/lib/mavenlink/resources/custom_field_value_spec.rb +69 -0
  34. data/spec/lib/mavenlink/resources/invoice_spec.rb +38 -0
  35. data/spec/lib/mavenlink/resources/workspace_group_spec.rb +147 -0
  36. data/spec/lib/mavenlink/resources/workspace_spec.rb +35 -0
  37. data/spec/spec_helper.rb +24 -0
  38. metadata +78 -0
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe Mavenlink::CustomFieldValue do
6
+ describe ".list" do
7
+ context "a subject type is provided" do
8
+ it "should be listable", :vcr do
9
+ custom_field_values = Mavenlink::CustomFieldValue.list("workspace_group")
10
+ expect(
11
+ a_request(:get, "#{Mavenlink.api_base}/custom_field_values")
12
+ .with(query: { subject_type: "workspace_group" })
13
+ ).to have_been_made
14
+ expect(custom_field_values.data).to be_a Array
15
+ expect(custom_field_values.first).to be_a Mavenlink::CustomFieldValue
16
+ end
17
+ end
18
+
19
+ context "no subject type is provided" do
20
+ it "should raise an error" do
21
+ expect do
22
+ Mavenlink::CustomFieldValue.list
23
+ end.to raise_error ArgumentError
24
+ end
25
+ end
26
+ end
27
+
28
+ describe ".retrieve" do
29
+ it "should be retrievable", :vcr do
30
+ custom_field_value = Mavenlink::CustomFieldValue.retrieve("314259865")
31
+
32
+ expect(a_request(:get, "#{Mavenlink.api_base}/custom_field_values/314259865")).to(
33
+ have_been_made
34
+ )
35
+ expect(custom_field_value).to be_a Mavenlink::CustomFieldValue
36
+ end
37
+ end
38
+
39
+ describe "#subject" do
40
+ let(:custom_field_value_attrs) do
41
+ {
42
+ "subject_type": "workspace_group",
43
+ "subject_id": 2223265,
44
+ "value": "ABCD",
45
+ "account_id": 6300575,
46
+ "custom_field_name": "Stripe ID",
47
+ "type": "string",
48
+ "display_value": "ABCD",
49
+ "can_edit": true,
50
+ "created_at": "2020-01-02T12:30:06-08:00",
51
+ "updated_at": "2020-01-02T12:30:06-08:00",
52
+ "custom_field_id": "602325",
53
+ "setter_id": "12304555",
54
+ "id": "314259865",
55
+ }
56
+ end
57
+
58
+ before do
59
+ allow(Mavenlink::WorkspaceGroup).to receive(:retrieve).with(2_223_265) do
60
+ Mavenlink::WorkspaceGroup.new(id: 2_223_265)
61
+ end
62
+ end
63
+ it "should retrieve the subject from the relevant class" do
64
+ custom_field_value = Mavenlink::CustomFieldValue.new(custom_field_value_attrs)
65
+ custom_field_value.subject
66
+ expect(Mavenlink::WorkspaceGroup).to have_received(:retrieve)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe Mavenlink::Invoice, type: :model do
6
+ it "should be retrievable", :vcr do
7
+ invoice = Mavenlink::Invoice.retrieve("8185325")
8
+
9
+ expect(a_request(:get, "#{Mavenlink.api_base}/invoices/8185325")).to(
10
+ have_been_made
11
+ )
12
+ expect(invoice).to be_a Mavenlink::Invoice
13
+ end
14
+
15
+ it "should be listable", :vcr do
16
+ invoices = Mavenlink::Invoice.list
17
+ expect(a_request(:get, "#{Mavenlink.api_base}/invoices")).to have_been_made
18
+ expect(invoices).to be_a Mavenlink::List
19
+ expect(invoices.first).to be_a Mavenlink::Invoice
20
+ end
21
+
22
+ it "should be creatable", :vcr do
23
+ invoice = Mavenlink::Invoice.create(
24
+ additional_items: [
25
+ notes: "",
26
+ amount: 250,
27
+ taxable: false,
28
+ workspace_id: 28370425,
29
+ ],
30
+ workspace_id: 28370425,
31
+ payment_schedule: 30,
32
+ draft: false,
33
+ supress_emails: true
34
+ )
35
+ expect(a_request(:post, "#{Mavenlink.api_base}/invoices")).to have_been_made
36
+ expect(invoice).to be_a Mavenlink::Invoice
37
+ end
38
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe Mavenlink::WorkspaceGroup do
6
+ describe ".retrieve" do
7
+ it "should be retrievable", :vcr do
8
+ workspace_group = Mavenlink::WorkspaceGroup.retrieve("2551145")
9
+
10
+ expect(a_request(:get, "#{Mavenlink.api_base}/workspace_groups/2551145")).to(
11
+ have_been_made
12
+ )
13
+ expect(workspace_group).to be_a Mavenlink::WorkspaceGroup
14
+ end
15
+ end
16
+
17
+ describe ".list" do
18
+ it "should be listable", :vcr do
19
+ workspace_groups = Mavenlink::WorkspaceGroup.list
20
+ expect(a_request(:get, "#{Mavenlink.api_base}/workspace_groups")).to have_been_made
21
+ expect(workspace_groups).to be_a Mavenlink::List
22
+ expect(workspace_groups.first).to be_a Mavenlink::WorkspaceGroup
23
+ end
24
+ end
25
+
26
+ describe ".list_workspaces" do
27
+ it "should list the Workspaces for the provided WorkspaceGroup id", :vcr do
28
+ workspaces = Mavenlink::WorkspaceGroup.list_workspaces(2551145)
29
+ expect(a_request(:get, "#{Mavenlink.api_base}/workspaces")
30
+ .with(query: { workspace_groups: 2551145 })).to have_been_made
31
+ expect(workspaces).to be_a Mavenlink::List
32
+ expect(workspaces.to_a.first).to be_a Mavenlink::Workspace
33
+ end
34
+ end
35
+
36
+ describe ".list_custom_field_values" do
37
+ # Setup a fake custom_field_values response that contains two values for
38
+ # our object and two for other objects.
39
+ # We can't rely on VCR here because we're trying to setup a specific
40
+ # scenario in the *response* and the real-world values could change at
41
+ # any time
42
+ # TODO: Probably move this to a factory / fixture file.
43
+
44
+ before do
45
+ # Numeric Literals just look weird in IDs
46
+ stub_request(:get, "#{Mavenlink.api_base}/custom_field_values")
47
+ .with(query: { subject_type: "workspace_group" })
48
+ .to_return(
49
+ headers: {
50
+ "Content-Type": "application/json",
51
+ },
52
+ body: JSON.generate(
53
+ count: 4,
54
+ results: [
55
+ { key: "custom_field_values", id: "111" },
56
+ { key: "custom_field_values", id: "222" },
57
+ { key: "custom_field_values", id: "888" },
58
+ { key: "custom_field_values", id: "999" },
59
+ ],
60
+ custom_field_values: {
61
+ "111": { id: "111",
62
+ subject_type: "workspace_group", subject_id: 2551145,
63
+ custom_field_name: "Foo", value: "Bar", },
64
+ "222": { id: "222",
65
+ subject_type: "workspace_group", subject_id: 2551145,
66
+ custom_field_name: "Stripe ID", value: "cus_xyz", },
67
+ "888": { id: "888",
68
+ subject_type: "workspace_group", subject_id: 9999999,
69
+ custom_field_name: "Bar", value: "I'm having the muffin", },
70
+ "999": { id: "999",
71
+ subject_type: "workspace_group", subject_id: 9999999,
72
+ custom_field_name: "Stripe ID", value: "cus_xyz", },
73
+ },
74
+ meta: {
75
+ count: 4,
76
+ page_count: 1,
77
+ page_number: 1,
78
+ page_size: 20,
79
+ }
80
+ )
81
+ )
82
+ end
83
+
84
+ let!(:custom_field_values) { Mavenlink::WorkspaceGroup.list_custom_field_values(2551145) }
85
+ it "should list CustomFieldValues" do
86
+ expect(
87
+ a_request(:get, "#{Mavenlink.api_base}/custom_field_values")
88
+ .with(query: { subject_type: "workspace_group" })
89
+ ).to have_been_made
90
+ expect(custom_field_values).to be_a Mavenlink::List
91
+ expect(custom_field_values.to_a.first).to be_a Mavenlink::CustomFieldValue
92
+ end
93
+
94
+ it "should only return the CustomFieldValues for the current object" do
95
+ expect(custom_field_values.count).to eq 2
96
+ end
97
+ end
98
+
99
+ describe "#workspaces" do
100
+ before do
101
+ allow(Mavenlink::WorkspaceGroup).to receive(:list_workspaces).and_return(true)
102
+ end
103
+ let(:workspace_group) { Mavenlink::WorkspaceGroup.new(id: 2551145) }
104
+
105
+ it "should defer to .list_workspaces with the current id" do
106
+ allow(Mavenlink::WorkspaceGroup).to receive :list_workspaces
107
+ workspace_group = Mavenlink::WorkspaceGroup.new(id: 2551145)
108
+
109
+ workspace_group.workspaces
110
+
111
+ expect(Mavenlink::WorkspaceGroup).to(
112
+ have_received(:list_workspaces).with(2551145)
113
+ )
114
+ end
115
+
116
+ it "should cache the result and not call list_workspaces twice" do
117
+ workspace_group.workspaces
118
+ workspace_group.workspaces
119
+
120
+ expect(Mavenlink::WorkspaceGroup).to(
121
+ have_received(:list_workspaces).with(2551145).once
122
+ )
123
+ end
124
+ end
125
+
126
+ describe "#custom_field_values", :vcr do
127
+ before do
128
+ allow(Mavenlink::WorkspaceGroup).to receive(:list_custom_field_values).and_return true
129
+ end
130
+
131
+ let(:workspace_group) { Mavenlink::WorkspaceGroup.new(id: 2551145) }
132
+ it "should defer to .list_custom_field_values with the current id" do
133
+ workspace_group.custom_field_values
134
+
135
+ expect(Mavenlink::WorkspaceGroup).to have_received(:list_custom_field_values).with(2551145)
136
+ end
137
+
138
+ it "should cache the result and not call list_custom_field_values twice" do
139
+ workspace_group.custom_field_values
140
+ workspace_group.custom_field_values
141
+
142
+ expect(Mavenlink::WorkspaceGroup).to(
143
+ have_received(:list_custom_field_values).with(2551145).once
144
+ )
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe Mavenlink::Workspace do
6
+ describe ".retrieve" do
7
+ it "should be retrievable", :vcr do
8
+ workspace = Mavenlink::Workspace.retrieve("28370425")
9
+
10
+ expect(a_request(:get, "#{Mavenlink.api_base}/workspaces/28370425")).to(
11
+ have_been_made
12
+ )
13
+ expect(workspace).to be_a Mavenlink::Workspace
14
+ end
15
+ end
16
+
17
+ describe ".list" do
18
+ it "should be listable", :vcr do
19
+ workspaces = Mavenlink::Workspace.list
20
+ expect(a_request(:get, "#{Mavenlink.api_base}/workspaces")).to have_been_made
21
+ expect(workspaces).to be_a Mavenlink::List
22
+ expect(workspaces.first).to be_a Mavenlink::Workspace
23
+ end
24
+ end
25
+
26
+ describe ".list_invoices" do
27
+ it "should list the Invoices for the provided Workspace id", :vcr do
28
+ invoices = Mavenlink::Workspace.list_invoices(28370425)
29
+ expect(a_request(:get, "#{Mavenlink.api_base}/invoices")
30
+ .with(query: { workspace_id: 28370425 })).to have_been_made
31
+ expect(invoices).to be_a Mavenlink::List
32
+ expect(invoices.to_a.first).to be_a Mavenlink::Invoice
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require "simplecov"
4
+ # SimpleCov.start
5
+
6
+ require "dotenv/load"
7
+ require "mavenlink"
8
+ require "rspec"
9
+ require "webmock/rspec"
10
+ require "vcr"
11
+
12
+ require_relative "../lib/mavenlink"
13
+
14
+ VCR.configure do |config|
15
+ config.cassette_library_dir = "fixtures/vcr_cassettes"
16
+ config.hook_into :webmock
17
+ config.configure_rspec_metadata!
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.before(:suite) do
22
+ Mavenlink.api_key = ENV["MAVENLINK_API_KEY"]
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mavenlink-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Adam Dawkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Inspired by Stripe's stripe-ruby
14
+ email: adam@dragondrop.uk
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".env"
20
+ - ".gitignore"
21
+ - ".rubocop.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - fixtures/vcr_cassettes/Mavenlink_CustomFieldValue/_list/a_subject_type_is_provided/should_be_listable.yml
28
+ - fixtures/vcr_cassettes/Mavenlink_CustomFieldValue/_retrieve/should_be_retrievable.yml
29
+ - fixtures/vcr_cassettes/Mavenlink_Invoice/_list/should_be_listable.yml
30
+ - fixtures/vcr_cassettes/Mavenlink_Invoice/_retrieve/should_be_retrievable.yml
31
+ - fixtures/vcr_cassettes/Mavenlink_Workspace/_list/should_be_listable.yml
32
+ - fixtures/vcr_cassettes/Mavenlink_Workspace/_list_invoices/should_list_the_Invoices_for_the_provided_Workspace_id.yml
33
+ - fixtures/vcr_cassettes/Mavenlink_Workspace/_retrieve/should_be_retrievable.yml
34
+ - fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_list/should_be_listable.yml
35
+ - fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_list_workspaces/should_list_the_Workspaces_for_the_provided_WorkspaceGroup_id.yml
36
+ - fixtures/vcr_cassettes/Mavenlink_WorkspaceGroup/_retrieve/should_be_retrievable.yml
37
+ - lib/mavenlink.rb
38
+ - lib/mavenlink/api_operations/request.rb
39
+ - lib/mavenlink/api_resource.rb
40
+ - lib/mavenlink/list.rb
41
+ - lib/mavenlink/resources.rb
42
+ - lib/mavenlink/resources/custom_field_value.rb
43
+ - lib/mavenlink/resources/invoice.rb
44
+ - lib/mavenlink/resources/workspace.rb
45
+ - lib/mavenlink/resources/workspace_group.rb
46
+ - lib/mavenlink/util.rb
47
+ - mavenlink-ruby.gemspec
48
+ - spec/.rubocop.yml
49
+ - spec/lib/mavenlink/list_spec.rb
50
+ - spec/lib/mavenlink/resources/custom_field_value_spec.rb
51
+ - spec/lib/mavenlink/resources/invoice_spec.rb
52
+ - spec/lib/mavenlink/resources/workspace_group_spec.rb
53
+ - spec/lib/mavenlink/resources/workspace_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: https://rubygems.org/gems/mavenlink-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.0.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Ruby Mavenlink API Wrapper
78
+ test_files: []